2019-10-13 07:59:52 +02:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\CodingStyle\Naming;
|
2019-05-01 13:15:18 +02:00
|
|
|
|
2024-12-01 00:43:07 +00:00
|
|
|
use RectorPrefix202412\Nette\Utils\Strings;
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Identifier;
|
|
|
|
use PhpParser\Node\Name;
|
|
|
|
use PhpParser\Node\Stmt\ClassLike;
|
2019-05-01 13:15:18 +02:00
|
|
|
final class ClassNaming
|
|
|
|
{
|
2019-05-26 01:15:21 +02:00
|
|
|
/**
|
2022-04-26 08:13:18 +00:00
|
|
|
* @param string|\PhpParser\Node\Name|\PhpParser\Node\Identifier|\PhpParser\Node\Stmt\ClassLike $name
|
2019-05-26 01:15:21 +02:00
|
|
|
*/
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getShortName($name) : string
|
2019-05-26 01:15:21 +02:00
|
|
|
{
|
2022-06-07 08:22:29 +00:00
|
|
|
if ($name instanceof ClassLike) {
|
2023-03-23 23:21:34 +00:00
|
|
|
if (!$name->name instanceof Identifier) {
|
2020-12-21 03:12:42 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return $this->getShortName($name->name);
|
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
if ($name instanceof Name || $name instanceof Identifier) {
|
2021-02-09 02:52:35 +01:00
|
|
|
$name = $name->toString();
|
2019-05-26 01:15:21 +02:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
$name = \trim($name, '\\');
|
2022-06-07 08:22:29 +00:00
|
|
|
$shortName = Strings::after($name, '\\', -1);
|
2021-11-28 18:05:13 +00:00
|
|
|
if (\is_string($shortName)) {
|
|
|
|
return $shortName;
|
|
|
|
}
|
|
|
|
return $name;
|
2019-05-01 13:15:18 +02:00
|
|
|
}
|
|
|
|
}
|