From 55a9883113733a4c90757e77c4e0f6f94152bf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 27 May 2025 12:03:40 +0200 Subject: [PATCH] feat: use namespaces and simplify comparasion --- src/ClassMap.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ClassMap.php b/src/ClassMap.php index 797efc6..307adbb 100644 --- a/src/ClassMap.php +++ b/src/ClassMap.php @@ -12,12 +12,15 @@ namespace Composer\ClassMapGenerator; +use Countable; +use InvalidArgumentException; +use OutOfBoundsException; use Composer\Pcre\Preg; /** * @author Jordi Boggiano */ -class ClassMap implements \Countable +class ClassMap implements Countable { /** * @var array @@ -89,15 +92,15 @@ public function getAmbiguousClasses($duplicatesFilter = '{/(test|fixture|example } if (true === $duplicatesFilter) { - throw new \InvalidArgumentException('$duplicatesFilter should be false or a string with a valid regex, got true.'); + throw new InvalidArgumentException('$duplicatesFilter should be false or a string with a valid regex, got true.'); } $ambiguousClasses = []; foreach ($this->ambiguousClasses as $class => $paths) { - $paths = array_filter($paths, function ($path) use ($duplicatesFilter) { + $paths = array_filter($paths, function ($path) use ($duplicatesFilter): bool { return !Preg::isMatch($duplicatesFilter, strtr($path, '\\', '/')); }); - if (\count($paths) > 0) { + if ($paths !== []) { $ambiguousClasses[$class] = array_values($paths); } } @@ -131,7 +134,7 @@ public function addClass(string $className, string $path): void public function getClassPath(string $className): string { if (!isset($this->map[$className])) { - throw new \OutOfBoundsException('Class '.$className.' is not present in the map'); + throw new OutOfBoundsException('Class '.$className.' is not present in the map'); } return $this->map[$className];