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