Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -4,12 +4,12 @@ namespace PhpParser\Node;
use PhpParser\NodeAbstract;
class Name extends NodeAbstract
{
/** @var string[] Parts of the name */
public $parts;
class Name extends NodeAbstract {
/** @var string Name as string */
public string $name;
private static $specialClassNames = [
/** @var array<string, bool> */
private static array $specialClassNames = [
'self' => true,
'parent' => true,
'static' => true,
@@ -18,16 +18,25 @@ class Name extends NodeAbstract
/**
* Constructs a name node.
*
* @param string|string[]|self $name Name as string, part array or Name instance (copy ctor)
* @param array $attributes Additional attributes
* @param string|string[]|self $name Name as string, part array or Name instance (copy ctor)
* @param array<string, mixed> $attributes Additional attributes
*/
public function __construct($name, array $attributes = []) {
final public function __construct($name, array $attributes = []) {
$this->attributes = $attributes;
$this->parts = self::prepareName($name);
$this->name = self::prepareName($name);
}
public function getSubNodeNames() : array {
return ['parts'];
public function getSubNodeNames(): array {
return ['name'];
}
/**
* Get parts of name (split by the namespace separator).
*
* @return string[] Parts of name
*/
public function getParts(): array {
return \explode('\\', $this->name);
}
/**
@@ -35,8 +44,11 @@ class Name extends NodeAbstract
*
* @return string First part of the name
*/
public function getFirst() : string {
return $this->parts[0];
public function getFirst(): string {
if (false !== $pos = \strpos($this->name, '\\')) {
return \substr($this->name, 0, $pos);
}
return $this->name;
}
/**
@@ -44,8 +56,11 @@ class Name extends NodeAbstract
*
* @return string Last part of the name
*/
public function getLast() : string {
return $this->parts[count($this->parts) - 1];
public function getLast(): string {
if (false !== $pos = \strrpos($this->name, '\\')) {
return \substr($this->name, $pos + 1);
}
return $this->name;
}
/**
@@ -53,8 +68,8 @@ class Name extends NodeAbstract
*
* @return bool Whether the name is unqualified
*/
public function isUnqualified() : bool {
return 1 === count($this->parts);
public function isUnqualified(): bool {
return false === \strpos($this->name, '\\');
}
/**
@@ -62,8 +77,8 @@ class Name extends NodeAbstract
*
* @return bool Whether the name is qualified
*/
public function isQualified() : bool {
return 1 < count($this->parts);
public function isQualified(): bool {
return false !== \strpos($this->name, '\\');
}
/**
@@ -71,7 +86,7 @@ class Name extends NodeAbstract
*
* @return bool Whether the name is fully qualified
*/
public function isFullyQualified() : bool {
public function isFullyQualified(): bool {
return false;
}
@@ -80,7 +95,7 @@ class Name extends NodeAbstract
*
* @return bool Whether the name is relative
*/
public function isRelative() : bool {
public function isRelative(): bool {
return false;
}
@@ -90,8 +105,8 @@ class Name extends NodeAbstract
*
* @return string String representation
*/
public function toString() : string {
return implode('\\', $this->parts);
public function toString(): string {
return $this->name;
}
/**
@@ -100,7 +115,7 @@ class Name extends NodeAbstract
*
* @return string String representation
*/
public function toCodeString() : string {
public function toCodeString(): string {
return $this->toString();
}
@@ -110,8 +125,8 @@ class Name extends NodeAbstract
*
* @return string Lowercased string representation
*/
public function toLowerString() : string {
return strtolower(implode('\\', $this->parts));
public function toLowerString(): string {
return strtolower($this->name);
}
/**
@@ -119,9 +134,8 @@ class Name extends NodeAbstract
*
* @return bool Whether identifier is a special class name
*/
public function isSpecialClassName() : bool {
return count($this->parts) === 1
&& isset(self::$specialClassNames[strtolower($this->parts[0])]);
public function isSpecialClassName(): bool {
return isset(self::$specialClassNames[strtolower($this->name)]);
}
/**
@@ -130,8 +144,8 @@ class Name extends NodeAbstract
*
* @return string String representation
*/
public function __toString() : string {
return implode('\\', $this->parts);
public function __toString(): string {
return $this->name;
}
/**
@@ -145,13 +159,22 @@ class Name extends NodeAbstract
*
* Offset and length have the same meaning as in array_slice().
*
* @param int $offset Offset to start the slice at (may be negative)
* @param int $offset Offset to start the slice at (may be negative)
* @param int|null $length Length of the slice (may be negative)
*
* @return static|null Sliced name
*/
public function slice(int $offset, int $length = null) {
$numParts = count($this->parts);
public function slice(int $offset, ?int $length = null) {
if ($offset === 1 && $length === null) {
// Short-circuit the common case.
if (false !== $pos = \strpos($this->name, '\\')) {
return new static(\substr($this->name, $pos + 1));
}
return null;
}
$parts = \explode('\\', $this->name);
$numParts = \count($parts);
$realOffset = $offset < 0 ? $offset + $numParts : $offset;
if ($realOffset < 0 || $realOffset > $numParts) {
@@ -162,7 +185,7 @@ class Name extends NodeAbstract
$realLength = $numParts - $realOffset;
} else {
$realLength = $length < 0 ? $length + $numParts - $realOffset : $length;
if ($realLength < 0 || $realLength > $numParts) {
if ($realLength < 0 || $realLength > $numParts - $realOffset) {
throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length));
}
}
@@ -172,7 +195,7 @@ class Name extends NodeAbstract
return null;
}
return new static(array_slice($this->parts, $realOffset, $realLength), $this->attributes);
return new static(array_slice($parts, $realOffset, $realLength), $this->attributes);
}
/**
@@ -186,49 +209,53 @@ class Name extends NodeAbstract
* Name::concat($namespace, $shortName)
* where $namespace is a Name node or null will work as expected.
*
* @param string|string[]|self|null $name1 The first name
* @param string|string[]|self|null $name2 The second name
* @param array $attributes Attributes to assign to concatenated name
* @param string|string[]|self|null $name1 The first name
* @param string|string[]|self|null $name2 The second name
* @param array<string, mixed> $attributes Attributes to assign to concatenated name
*
* @return static|null Concatenated name
*/
public static function concat($name1, $name2, array $attributes = []) {
if (null === $name1 && null === $name2) {
return null;
} elseif (null === $name1) {
return new static(self::prepareName($name2), $attributes);
} elseif (null === $name2) {
return new static(self::prepareName($name1), $attributes);
}
if (null === $name1) {
return new static($name2, $attributes);
}
if (null === $name2) {
return new static($name1, $attributes);
} else {
return new static(
array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes
self::prepareName($name1) . '\\' . self::prepareName($name2), $attributes
);
}
}
/**
* Prepares a (string, array or Name node) name for use in name changing methods by converting
* it to an array.
* it to a string.
*
* @param string|string[]|self $name Name to prepare
*
* @return string[] Prepared name
* @return string Prepared name
*/
private static function prepareName($name) : array {
private static function prepareName($name): string {
if (\is_string($name)) {
if ('' === $name) {
throw new \InvalidArgumentException('Name cannot be empty');
}
return explode('\\', $name);
} elseif (\is_array($name)) {
return $name;
}
if (\is_array($name)) {
if (empty($name)) {
throw new \InvalidArgumentException('Name cannot be empty');
}
return $name;
} elseif ($name instanceof self) {
return $name->parts;
return implode('\\', $name);
}
if ($name instanceof self) {
return $name->name;
}
throw new \InvalidArgumentException(
@@ -236,7 +263,7 @@ class Name extends NodeAbstract
);
}
public function getType() : string {
public function getType(): string {
return 'Name';
}
}