Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Node / Name.php
index 7b8c8e2324809952669e5c7fc4f1b55768d17abc..5d923d02a84a312ad5ca288dd6e01f416d067049 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
 
 namespace PhpParser\Node;
 
@@ -11,19 +11,25 @@ class Name extends NodeAbstract
      */
     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 @@ class Name extends NodeAbstract
      *
      * @return string First part of the name
      */
-    public function getFirst() {
+    public function getFirst() : string {
         return $this->parts[0];
     }
 
@@ -40,7 +46,7 @@ class Name extends NodeAbstract
      *
      * @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 @@ class Name extends NodeAbstract
      *
      * @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 @@ class Name extends NodeAbstract
      *
      * @return bool Whether the name is qualified
      */
-    public function isQualified() {
+    public function isQualified() : bool {
         return 1 < count($this->parts);
     }
 
@@ -67,7 +73,7 @@ class Name extends NodeAbstract
      *
      * @return bool Whether the name is fully qualified
      */
-    public function isFullyQualified() {
+    public function isFullyQualified() : bool {
         return false;
     }
 
@@ -76,27 +82,57 @@ class Name extends NodeAbstract
      *
      * @return bool Whether the name is relative
      */
-    public function isRelative() {
+    public function isRelative() : bool {
         return false;
     }
 
     /**
-     * Returns a string representation of the name by imploding the namespace parts with the
-     * namespace separator.
+     * 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() {
+    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() {
+    public function __toString() : string {
         return implode('\\', $this->parts);
     }
 
@@ -116,7 +152,7 @@ class Name extends NodeAbstract
      *
      * @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 @@ class Name extends NodeAbstract
      *     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 @@ class Name extends NodeAbstract
             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 @@ class Name extends NodeAbstract
      * 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 @@ class Name extends NodeAbstract
             'Expected string, array of parts or Name instance'
         );
     }
+    
+    public function getType() : string {
+        return 'Name';
+    }
 }