rector/rules/Naming/NamespaceMatcher.php
Tomas Votruba fff9179119 Updated Rector to commit f7e99868356cf76b167e1010d5f9b3694202596e
f7e9986835 [PHP 8.0] Add downgrade for str_starts_with() (#126)
2021-05-30 10:12:56 +00:00

24 lines
730 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Naming;
use Rector\Renaming\ValueObject\RenamedNamespace;
final class NamespaceMatcher
{
/**
* @param string[] $oldToNewNamespace
*/
public function matchRenamedNamespace(string $name, array $oldToNewNamespace) : ?\Rector\Renaming\ValueObject\RenamedNamespace
{
\krsort($oldToNewNamespace);
/** @var string $oldNamespace */
foreach ($oldToNewNamespace as $oldNamespace => $newNamespace) {
if (\strncmp($name, $oldNamespace, \strlen($oldNamespace)) === 0) {
return new \Rector\Renaming\ValueObject\RenamedNamespace($name, $oldNamespace, $newNamespace);
}
}
return null;
}
}