rector/rules/Naming/RectorNamingInflector.php
Tomas Votruba b2218b1dc3 Updated Rector to commit a7fe982fcbe5901a7e072ec3911cdd201536eb01
a7fe982fcb [Renaming] Handle Rename before AttributeGroup on RenameClassRector (#1481)
2021-12-14 08:14:22 +00:00

35 lines
1.0 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\Naming;
use RectorPrefix20211214\Doctrine\Inflector\Inflector;
use RectorPrefix20211214\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)$#';
/**
* @readonly
* @var \Doctrine\Inflector\Inflector
*/
private $inflector;
public function __construct(\RectorPrefix20211214\Doctrine\Inflector\Inflector $inflector)
{
$this->inflector = $inflector;
}
public function singularize(string $name) : string
{
$matches = \RectorPrefix20211214\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;
}
}