Skip to content

feat: use namespaces and simplify comparison #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/ClassMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@

namespace Composer\ClassMapGenerator;

use Countable;
use InvalidArgumentException;
use OutOfBoundsException;
use Composer\Pcre\Preg;

/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ClassMap implements \Countable
class ClassMap implements Countable
{
/**
* @var array<class-string, non-empty-string>
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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];
Expand Down