diff --git a/src/Model/Filter/AbstractListFilter.php b/src/Model/Filter/AbstractListFilter.php index f940be7e8e923ca0c478d4ed3a8ecd06e40fd239..296d7cd8a5cbb021790dc480ec6bc79a840485f6 100644 --- a/src/Model/Filter/AbstractListFilter.php +++ b/src/Model/Filter/AbstractListFilter.php @@ -34,16 +34,25 @@ abstract class AbstractListFilter implements ClassFilterInterface private $allowed = []; /** - * @var boolena + * @var bool */ private $notFound; + /** + * AbstractListFilter constructor. + * @param array $allowed + * @param bool $notFound + */ public function __construct(array $allowed, $notFound = false) { $this->allowed = array_map([$this, 'normalize'], $allowed); $this->notFound = $notFound; } + /** + * @param ReflectionClass $class + * @return bool + */ public function accept(ReflectionClass $class) { $tested = $this->normalize($this->extract($class)); @@ -56,6 +65,9 @@ abstract class AbstractListFilter implements ClassFilterInterface return $this->notFound; } + /** + * @param array $conf + */ public function toConfig(array &$conf) { $key = $this->notFound ? 'exclude' : 'include'; @@ -70,21 +82,20 @@ abstract class AbstractListFilter implements ClassFilterInterface * * @return string */ - abstract protected function normalize($value); + abstract protected function normalize($value): string; /** * @param ReflectionClass $class * * @return string */ - abstract protected function extract(ReflectionClass $class); + abstract protected function extract(ReflectionClass $class): string; /** - * @param string $value - * @param mixed $tested - * @param mixed $reference + * @param mixed $tested + * @param mixed $reference * * @return bool */ - abstract protected function matches($tested, $reference); + abstract protected function matches($tested, $reference): bool; } diff --git a/src/Model/Filter/ClassFilter.php b/src/Model/Filter/ClassFilter.php index c46cad7e93d7f10470c50b5e2ba2fca6e0dc801c..570da3cb1cf1217e835ef86cfd506f52c93a73e0 100644 --- a/src/Model/Filter/ClassFilter.php +++ b/src/Model/Filter/ClassFilter.php @@ -27,19 +27,31 @@ use ReflectionClass; */ class ClassFilter extends AbstractListFilter { + /** + * @var string + */ public const CONF_TYPE = 'classes'; - protected function extract(ReflectionClass $class) + /** + * {@inheritDoc} + */ + protected function extract(ReflectionClass $class): string { return $class->getName(); } - protected function matches($tested, $reference) + /** + * {@inheritDoc} + */ + protected function matches($tested, $reference): bool { return $tested === $reference; } - protected function normalize($className) + /** + * {@inheritDoc} + */ + protected function normalize($className): string { return trim($className, '\\'); } diff --git a/src/Model/Filter/DirectoryFilter.php b/src/Model/Filter/DirectoryFilter.php index 44fa2b08ca2ae14798935b99feea735c9c9c0177..9c1d7f4bf76e0f090d556db6070e7eed86eda330 100644 --- a/src/Model/Filter/DirectoryFilter.php +++ b/src/Model/Filter/DirectoryFilter.php @@ -27,19 +27,38 @@ use ReflectionClass; */ class DirectoryFilter extends AbstractListFilter { + /** + * @var string + */ 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()); } - protected function matches($tested, $reference) + /** + * @param mixed $tested + * @param mixed $reference + * @return bool + */ + protected function matches($tested, $reference): bool { 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; } diff --git a/src/Model/Filter/NamespaceFilter.php b/src/Model/Filter/NamespaceFilter.php index f1e8f115fdf5ace5e3ff680fe7f1c50e92eeb6d5..4e7ccdc66705fddfbd23b9272a26f6b1f96f1801 100644 --- a/src/Model/Filter/NamespaceFilter.php +++ b/src/Model/Filter/NamespaceFilter.php @@ -29,17 +29,26 @@ class NamespaceFilter extends AbstractListFilter { public const CONF_TYPE = 'namespaces'; - protected function extract(ReflectionClass $class) + /** + * {@inheritDoc} + */ + protected function extract(ReflectionClass $class): string { return $class->getNamespaceName(); } - protected function matches($tested, $reference) + /** + * {@inheritDoc} + */ + protected function matches($tested, $reference): bool { return strpos($tested, $reference) === 0; } - protected function normalize($namespace) + /** + * {@inheritDoc} + */ + protected function normalize($namespace): string { return trim($namespace, '\\') . '\\'; } diff --git a/src/Model/Graph.php b/src/Model/Graph.php index b4a7507020164aad0b5151ef675a0c8739e56547..119696a03a85c2b8e587f85491a78e19475357ec 100644 --- a/src/Model/Graph.php +++ b/src/Model/Graph.php @@ -38,20 +38,32 @@ class Graph implements GraphInterface */ private $finder; + /** + * Graph constructor. + * @param ClassVisitorInterface $visitor + * @param FinderInterface $finder + */ public function __construct(ClassVisitorInterface $visitor, FinderInterface $finder) { $this->visitor = $visitor; $this->finder = $finder; } - public function visitAll() + /** + * + */ + public function visitAll(): void { foreach ($this->finder->getIterator() as $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"); $this->visitor->writeTo($writer);