mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-15 13:25:30 +01:00
29 lines
679 B
PHP
29 lines
679 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\Naming;
|
|
|
|
use Nette\Utils\Strings;
|
|
use Rector\Renaming\ValueObject\RenamedNamespace;
|
|
|
|
final class NamespaceMatcher
|
|
{
|
|
/**
|
|
* @param string[] $oldToNewNamespace
|
|
*/
|
|
public function matchRenamedNamespace(string $name, array $oldToNewNamespace): ?RenamedNamespace
|
|
{
|
|
krsort($oldToNewNamespace);
|
|
|
|
/** @var string $oldNamespace */
|
|
foreach ($oldToNewNamespace as $oldNamespace => $newNamespace) {
|
|
if (Strings::startsWith($name, $oldNamespace)) {
|
|
return new RenamedNamespace($name, $oldNamespace, $newNamespace);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|