From 3fe87e8e825777ff9b0566a482b5f2d05a3b844d Mon Sep 17 00:00:00 2001 From: Perreal Guillaume <guillaume.perreal@irstea.fr> Date: Thu, 4 Jul 2019 14:58:26 +0200 Subject: [PATCH] CS et correction d'un bug dans les filters. --- src/Model/Filter/AbstractListFilter.php | 25 ++++++++++++++++++------- src/Model/Filter/ClassFilter.php | 18 +++++++++++++++--- src/Model/Filter/DirectoryFilter.php | 25 ++++++++++++++++++++++--- src/Model/Filter/NamespaceFilter.php | 15 ++++++++++++--- src/Model/Graph.php | 16 ++++++++++++++-- 5 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/Model/Filter/AbstractListFilter.php b/src/Model/Filter/AbstractListFilter.php index f940be7..296d7cd 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 c46cad7..570da3c 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 44fa2b0..9c1d7f4 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 f1e8f11..4e7ccdc 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 b4a7507..119696a 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); -- GitLab