mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-08 17:10:54 +01:00
54f8d6dc33
da4d598bf0
[PHPStan 1.0] resolve FunctionReflection getFileName() from main interface (#1117)
34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Naming;
|
|
|
|
use RectorPrefix20211031\Doctrine\Inflector\Inflector;
|
|
use RectorPrefix20211031\Nette\Utils\Strings;
|
|
final class RectorNamingInflector
|
|
{
|
|
/**
|
|
* @var string
|
|
* @see https://regex101.com/r/VqVvke/3
|
|
*/
|
|
private const DATA_INFO_SUFFIX_REGEX = '#^(?<prefix>.+)(?<suffix>Data|Info)$#';
|
|
/**
|
|
* @var \Doctrine\Inflector\Inflector
|
|
*/
|
|
private $inflector;
|
|
public function __construct(\RectorPrefix20211031\Doctrine\Inflector\Inflector $inflector)
|
|
{
|
|
$this->inflector = $inflector;
|
|
}
|
|
public function singularize(string $name) : string
|
|
{
|
|
$matches = \RectorPrefix20211031\Nette\Utils\Strings::match($name, self::DATA_INFO_SUFFIX_REGEX);
|
|
if ($matches === null) {
|
|
return $this->inflector->singularize($name);
|
|
}
|
|
$singularized = $this->inflector->singularize($matches['prefix']);
|
|
$uninflectable = $matches['suffix'];
|
|
return $singularized . $uninflectable;
|
|
}
|
|
}
|