Files
apimacro/vendor/nikic/php-parser/lib/PhpParser/Node/Identifier.php

86 lines
2.1 KiB
PHP
Raw Normal View History

2024-05-07 12:17:25 +02:00
<?php declare(strict_types=1);
namespace PhpParser\Node;
use PhpParser\NodeAbstract;
/**
* Represents a non-namespaced name. Namespaced names are represented using Name nodes.
*/
2024-05-17 12:24:19 +00:00
class Identifier extends NodeAbstract {
2024-08-13 13:44:16 +00:00
/**
* @psalm-var non-empty-string
* @var string Identifier as string
*/
2024-05-17 12:24:19 +00:00
public string $name;
2024-05-07 12:17:25 +02:00
2024-05-17 12:24:19 +00:00
/** @var array<string, bool> */
private static array $specialClassNames = [
2024-05-07 12:17:25 +02:00
'self' => true,
'parent' => true,
'static' => true,
];
/**
* Constructs an identifier node.
*
2024-05-17 12:24:19 +00:00
* @param string $name Identifier as string
* @param array<string, mixed> $attributes Additional attributes
2024-05-07 12:17:25 +02:00
*/
public function __construct(string $name, array $attributes = []) {
2024-08-13 13:44:16 +00:00
if ($name === '') {
throw new \InvalidArgumentException('Identifier name cannot be empty');
}
2024-05-07 12:17:25 +02:00
$this->attributes = $attributes;
$this->name = $name;
}
2024-05-17 12:24:19 +00:00
public function getSubNodeNames(): array {
2024-05-07 12:17:25 +02:00
return ['name'];
}
/**
* Get identifier as string.
*
2024-08-13 13:44:16 +00:00
* @psalm-return non-empty-string
2024-05-07 12:17:25 +02:00
* @return string Identifier as string.
*/
2024-05-17 12:24:19 +00:00
public function toString(): string {
2024-05-07 12:17:25 +02:00
return $this->name;
}
/**
* Get lowercased identifier as string.
*
2024-08-13 13:44:16 +00:00
* @psalm-return non-empty-string
2024-05-07 12:17:25 +02:00
* @return string Lowercased identifier as string
*/
2024-05-17 12:24:19 +00:00
public function toLowerString(): string {
2024-05-07 12:17:25 +02:00
return strtolower($this->name);
}
/**
* Checks whether the identifier is a special class name (self, parent or static).
*
* @return bool Whether identifier is a special class name
*/
2024-05-17 12:24:19 +00:00
public function isSpecialClassName(): bool {
2024-05-07 12:17:25 +02:00
return isset(self::$specialClassNames[strtolower($this->name)]);
}
/**
* Get identifier as string.
*
2024-08-13 13:44:16 +00:00
* @psalm-return non-empty-string
2024-05-07 12:17:25 +02:00
* @return string Identifier as string
*/
2024-05-17 12:24:19 +00:00
public function __toString(): string {
2024-05-07 12:17:25 +02:00
return $this->name;
}
2024-05-17 12:24:19 +00:00
public function getType(): string {
2024-05-07 12:17:25 +02:00
return 'Identifier';
}
}