Une mise-à-jour est prévue le 9 juillet entre 13:00 et 14:00. Le service sera inaccessible ou instable pendant cette période. Merci de votre compréhension.

Commit 3fe87e8e authored by Guillaume Perréal's avatar Guillaume Perréal

CS et correction d'un bug dans les filters.

parent 6b09c22c
...@@ -34,16 +34,25 @@ abstract class AbstractListFilter implements ClassFilterInterface ...@@ -34,16 +34,25 @@ abstract class AbstractListFilter implements ClassFilterInterface
private $allowed = []; private $allowed = [];
/** /**
* @var boolena * @var bool
*/ */
private $notFound; private $notFound;
/**
* AbstractListFilter constructor.
* @param array $allowed
* @param bool $notFound
*/
public function __construct(array $allowed, $notFound = false) public function __construct(array $allowed, $notFound = false)
{ {
$this->allowed = array_map([$this, 'normalize'], $allowed); $this->allowed = array_map([$this, 'normalize'], $allowed);
$this->notFound = $notFound; $this->notFound = $notFound;
} }
/**
* @param ReflectionClass $class
* @return bool
*/
public function accept(ReflectionClass $class) public function accept(ReflectionClass $class)
{ {
$tested = $this->normalize($this->extract($class)); $tested = $this->normalize($this->extract($class));
...@@ -56,6 +65,9 @@ abstract class AbstractListFilter implements ClassFilterInterface ...@@ -56,6 +65,9 @@ abstract class AbstractListFilter implements ClassFilterInterface
return $this->notFound; return $this->notFound;
} }
/**
* @param array $conf
*/
public function toConfig(array &$conf) public function toConfig(array &$conf)
{ {
$key = $this->notFound ? 'exclude' : 'include'; $key = $this->notFound ? 'exclude' : 'include';
...@@ -70,21 +82,20 @@ abstract class AbstractListFilter implements ClassFilterInterface ...@@ -70,21 +82,20 @@ abstract class AbstractListFilter implements ClassFilterInterface
* *
* @return string * @return string
*/ */
abstract protected function normalize($value); abstract protected function normalize($value): string;
/** /**
* @param ReflectionClass $class * @param ReflectionClass $class
* *
* @return string * @return string
*/ */
abstract protected function extract(ReflectionClass $class); abstract protected function extract(ReflectionClass $class): string;
/** /**
* @param string $value
* @param mixed $tested * @param mixed $tested
* @param mixed $reference * @param mixed $reference
* *
* @return bool * @return bool
*/ */
abstract protected function matches($tested, $reference); abstract protected function matches($tested, $reference): bool;
} }
...@@ -27,19 +27,31 @@ use ReflectionClass; ...@@ -27,19 +27,31 @@ use ReflectionClass;
*/ */
class ClassFilter extends AbstractListFilter class ClassFilter extends AbstractListFilter
{ {
/**
* @var string
*/
public const CONF_TYPE = 'classes'; public const CONF_TYPE = 'classes';
protected function extract(ReflectionClass $class) /**
* {@inheritDoc}
*/
protected function extract(ReflectionClass $class): string
{ {
return $class->getName(); return $class->getName();
} }
protected function matches($tested, $reference) /**
* {@inheritDoc}
*/
protected function matches($tested, $reference): bool
{ {
return $tested === $reference; return $tested === $reference;
} }
protected function normalize($className) /**
* {@inheritDoc}
*/
protected function normalize($className): string
{ {
return trim($className, '\\'); return trim($className, '\\');
} }
......
...@@ -27,19 +27,38 @@ use ReflectionClass; ...@@ -27,19 +27,38 @@ use ReflectionClass;
*/ */
class DirectoryFilter extends AbstractListFilter class DirectoryFilter extends AbstractListFilter
{ {
/**
* @var string
*/
public const CONF_TYPE = 'directories'; public const CONF_TYPE = 'directories';
protected function extract(ReflectionClass $class) /**
* {@inheritDoc}
*/
protected function extract(ReflectionClass $class): string
{ {
$filename = $class->getFileName();
if ($filename === false) {
return '';
}
return dirname($class->getFileName()); return dirname($class->getFileName());
} }
protected function matches($tested, $reference) /**
* @param mixed $tested
* @param mixed $reference
* @return bool
*/
protected function matches($tested, $reference): bool
{ {
return strpos($tested, $reference) === 0; return strpos($tested, $reference) === 0;
} }
protected function normalize($path) /**
* @param string $path
* @return string
*/
protected function normalize($path): string
{ {
return rtrim(strtr($path, '/\\', DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; return rtrim(strtr($path, '/\\', DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
} }
......
...@@ -29,17 +29,26 @@ class NamespaceFilter extends AbstractListFilter ...@@ -29,17 +29,26 @@ class NamespaceFilter extends AbstractListFilter
{ {
public const CONF_TYPE = 'namespaces'; public const CONF_TYPE = 'namespaces';
protected function extract(ReflectionClass $class) /**
* {@inheritDoc}
*/
protected function extract(ReflectionClass $class): string
{ {
return $class->getNamespaceName(); return $class->getNamespaceName();
} }
protected function matches($tested, $reference) /**
* {@inheritDoc}
*/
protected function matches($tested, $reference): bool
{ {
return strpos($tested, $reference) === 0; return strpos($tested, $reference) === 0;
} }
protected function normalize($namespace) /**
* {@inheritDoc}
*/
protected function normalize($namespace): string
{ {
return trim($namespace, '\\') . '\\'; return trim($namespace, '\\') . '\\';
} }
......
...@@ -38,20 +38,32 @@ class Graph implements GraphInterface ...@@ -38,20 +38,32 @@ class Graph implements GraphInterface
*/ */
private $finder; private $finder;
/**
* Graph constructor.
* @param ClassVisitorInterface $visitor
* @param FinderInterface $finder
*/
public function __construct(ClassVisitorInterface $visitor, FinderInterface $finder) public function __construct(ClassVisitorInterface $visitor, FinderInterface $finder)
{ {
$this->visitor = $visitor; $this->visitor = $visitor;
$this->finder = $finder; $this->finder = $finder;
} }
public function visitAll() /**
*
*/
public function visitAll(): void
{ {
foreach ($this->finder->getIterator() as $class) { foreach ($this->finder->getIterator() as $class) {
$this->visitor->visitClass($class); $this->visitor->visitClass($class);
} }
} }
public function writeTo(WriterInterface $writer) /**
* @param WriterInterface $writer
* @return $this
*/
public function writeTo(WriterInterface $writer): self
{ {
$writer->write("@startuml@\n"); $writer->write("@startuml@\n");
$this->visitor->writeTo($writer); $this->visitor->writeTo($writer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment