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
925 B
PHP
34 lines
925 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\CodingStyle\Naming;
|
|
|
|
use RectorPrefix202412\Nette\Utils\Strings;
|
|
use PhpParser\Node\Identifier;
|
|
use PhpParser\Node\Name;
|
|
use PhpParser\Node\Stmt\ClassLike;
|
|
final class ClassNaming
|
|
{
|
|
/**
|
|
* @param string|\PhpParser\Node\Name|\PhpParser\Node\Identifier|\PhpParser\Node\Stmt\ClassLike $name
|
|
*/
|
|
public function getShortName($name) : string
|
|
{
|
|
if ($name instanceof ClassLike) {
|
|
if (!$name->name instanceof Identifier) {
|
|
return '';
|
|
}
|
|
return $this->getShortName($name->name);
|
|
}
|
|
if ($name instanceof Name || $name instanceof Identifier) {
|
|
$name = $name->toString();
|
|
}
|
|
$name = \trim($name, '\\');
|
|
$shortName = Strings::after($name, '\\', -1);
|
|
if (\is_string($shortName)) {
|
|
return $shortName;
|
|
}
|
|
return $name;
|
|
}
|
|
}
|