-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathRectorNamingInflector.php
More file actions
34 lines (26 loc) · 819 Bytes
/
RectorNamingInflector.php
File metadata and controls
34 lines (26 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
namespace Rector\Naming;
use Doctrine\Inflector\Inflector;
use Nette\Utils\Strings;
final readonly class RectorNamingInflector
{
/**
* @see https://regex101.com/r/VqVvke/3
*/
private const string DATA_INFO_SUFFIX_REGEX = '#^(?<prefix>.+)(?<suffix>Data|Info)$#';
public function __construct(
private 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((string) $matches['prefix']);
$uninflectable = $matches['suffix'];
return $singularized . $uninflectable;
}
}