mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
c56fdd2b7f
1b68ff48b8
[automated] Apply Coding Standard (#6524)
34 lines
935 B
PHP
34 lines
935 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Naming;
|
|
|
|
use RectorPrefix202412\Doctrine\Inflector\Inflector;
|
|
use RectorPrefix202412\Nette\Utils\Strings;
|
|
final class RectorNamingInflector
|
|
{
|
|
/**
|
|
* @readonly
|
|
*/
|
|
private Inflector $inflector;
|
|
/**
|
|
* @var string
|
|
* @see https://regex101.com/r/VqVvke/3
|
|
*/
|
|
private const DATA_INFO_SUFFIX_REGEX = '#^(?<prefix>.+)(?<suffix>Data|Info)$#';
|
|
public function __construct(Inflector $inflector)
|
|
{
|
|
$this->inflector = $inflector;
|
|
}
|
|
public function singularize(string $name) : string
|
|
{
|
|
$matches = 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;
|
|
}
|
|
}
|