Mercurial > hg > isophonics-drupal-site
diff vendor/nikic/php-parser/lib/PhpParser/Node/Name.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/vendor/nikic/php-parser/lib/PhpParser/Node/Name.php Fri Feb 23 15:52:07 2018 +0000 +++ b/vendor/nikic/php-parser/lib/PhpParser/Node/Name.php Mon Apr 23 09:33:26 2018 +0100 @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); namespace PhpParser\Node; @@ -11,19 +11,25 @@ */ public $parts; + private static $specialClassNames = [ + 'self' => true, + 'parent' => true, + 'static' => true, + ]; + /** * Constructs a name node. * - * @param string|array|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 $attributes Additional attributes */ - public function __construct($name, array $attributes = array()) { + public function __construct($name, array $attributes = []) { parent::__construct($attributes); $this->parts = self::prepareName($name); } - public function getSubNodeNames() { - return array('parts'); + public function getSubNodeNames() : array { + return ['parts']; } /** @@ -31,7 +37,7 @@ * * @return string First part of the name */ - public function getFirst() { + public function getFirst() : string { return $this->parts[0]; } @@ -40,7 +46,7 @@ * * @return string Last part of the name */ - public function getLast() { + public function getLast() : string { return $this->parts[count($this->parts) - 1]; } @@ -49,8 +55,8 @@ * * @return bool Whether the name is unqualified */ - public function isUnqualified() { - return 1 == count($this->parts); + public function isUnqualified() : bool { + return 1 === count($this->parts); } /** @@ -58,7 +64,7 @@ * * @return bool Whether the name is qualified */ - public function isQualified() { + public function isQualified() : bool { return 1 < count($this->parts); } @@ -67,7 +73,7 @@ * * @return bool Whether the name is fully qualified */ - public function isFullyQualified() { + public function isFullyQualified() : bool { return false; } @@ -76,27 +82,57 @@ * * @return bool Whether the name is relative */ - public function isRelative() { + public function isRelative() : bool { return false; } /** + * Returns a string representation of the name itself, without taking taking the name type into + * account (e.g., not including a leading backslash for fully qualified names). + * + * @return string String representation + */ + public function toString() : string { + return implode('\\', $this->parts); + } + + /** + * Returns a string representation of the name as it would occur in code (e.g., including + * leading backslash for fully qualified names. + * + * @return string String representation + */ + public function toCodeString() : string { + return $this->toString(); + } + + /** + * Returns lowercased string representation of the name, without taking the name type into + * account (e.g., no leading backslash for fully qualified names). + * + * @return string Lowercased string representation + */ + public function toLowerString() : string { + return strtolower(implode('\\', $this->parts)); + } + + /** + * Checks whether the identifier is a special class name (self, parent or static). + * + * @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])]); + } + + /** * Returns a string representation of the name by imploding the namespace parts with the * namespace separator. * * @return string String representation */ - public function toString() { - return implode('\\', $this->parts); - } - - /** - * Returns a string representation of the name by imploding the namespace parts with the - * namespace separator. - * - * @return string String representation - */ - public function __toString() { + public function __toString() : string { return implode('\\', $this->parts); } @@ -116,7 +152,7 @@ * * @return static|null Sliced name */ - public function slice($offset, $length = null) { + public function slice(int $offset, int $length = null) { $numParts = count($this->parts); $realOffset = $offset < 0 ? $offset + $numParts : $offset; @@ -152,9 +188,9 @@ * Name::concat($namespace, $shortName) * where $namespace is a Name node or null will work as expected. * - * @param string|array|self|null $name1 The first name - * @param string|array|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 $attributes Attributes to assign to concatenated name * * @return static|null Concatenated name */ @@ -163,7 +199,7 @@ return null; } elseif (null === $name1) { return new static(self::prepareName($name2), $attributes); - } else if (null === $name2) { + } elseif (null === $name2) { return new static(self::prepareName($name1), $attributes); } else { return new static( @@ -176,14 +212,22 @@ * Prepares a (string, array or Name node) name for use in name changing methods by converting * it to an array. * - * @param string|array|self $name Name to prepare + * @param string|string[]|self $name Name to prepare * - * @return array Prepared name + * @return string[] Prepared name */ - private static function prepareName($name) { + private static function prepareName($name) : array { if (\is_string($name)) { + if ('' === $name) { + throw new \InvalidArgumentException('Name cannot be empty'); + } + return explode('\\', $name); } elseif (\is_array($name)) { + if (empty($name)) { + throw new \InvalidArgumentException('Name cannot be empty'); + } + return $name; } elseif ($name instanceof self) { return $name->parts; @@ -193,4 +237,8 @@ 'Expected string, array of parts or Name instance' ); } + + public function getType() : string { + return 'Name'; + } }