diff vendor/phpunit/php-token-stream/src/Token/Stream.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children
line wrap: on
line diff
--- a/vendor/phpunit/php-token-stream/src/Token/Stream.php	Mon Apr 23 09:33:26 2018 +0100
+++ b/vendor/phpunit/php-token-stream/src/Token/Stream.php	Mon Apr 23 09:46:53 2018 +0100
@@ -1,6 +1,6 @@
 <?php
 /*
- * This file is part of the PHP_TokenStream package.
+ * This file is part of php-token-stream.
  *
  * (c) Sebastian Bergmann <sebastian@phpunit.de>
  *
@@ -10,19 +10,13 @@
 
 /**
  * A stream of PHP tokens.
- *
- * @author    Sebastian Bergmann <sebastian@phpunit.de>
- * @copyright Sebastian Bergmann <sebastian@phpunit.de>
- * @license   http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
- * @link      http://github.com/sebastianbergmann/php-token-stream/tree
- * @since     Class available since Release 1.0.0
  */
 class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
 {
     /**
      * @var array
      */
-    protected static $customTokens = array(
+    protected static $customTokens = [
         '(' => 'PHP_Token_OPEN_BRACKET',
         ')' => 'PHP_Token_CLOSE_BRACKET',
         '[' => 'PHP_Token_OPEN_SQUARE',
@@ -51,7 +45,7 @@
         '^' => 'PHP_Token_CARET',
         '~' => 'PHP_Token_TILDE',
         '`' => 'PHP_Token_BACKTICK'
-    );
+    ];
 
     /**
      * @var string
@@ -61,17 +55,17 @@
     /**
      * @var array
      */
-    protected $tokens = array();
+    protected $tokens = [];
 
     /**
-     * @var integer
+     * @var int
      */
     protected $position = 0;
 
     /**
      * @var array
      */
-    protected $linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0);
+    protected $linesOfCode = ['loc' => 0, 'cloc' => 0, 'ncloc' => 0];
 
     /**
      * @var array
@@ -101,7 +95,7 @@
     /**
      * @var array
      */
-    protected $lineToFunctionMap = array();
+    protected $lineToFunctionMap = [];
 
     /**
      * Constructor.
@@ -123,7 +117,7 @@
      */
     public function __destruct()
     {
-        $this->tokens = array();
+        $this->tokens = [];
     }
 
     /**
@@ -142,7 +136,6 @@
 
     /**
      * @return string
-     * @since  Method available since Release 1.1.0
      */
     public function getFilename()
     {
@@ -174,9 +167,9 @@
 
                 if ($lastNonWhitespaceTokenWasDoubleColon && $name == 'CLASS') {
                     $name = 'CLASS_NAME_CONSTANT';
-                } elseif ($name == 'USE' && isset($tokens[$i+2][0]) && $tokens[$i+2][0] == T_FUNCTION) {
+                } elseif ($name == 'USE' && isset($tokens[$i + 2][0]) && $tokens[$i + 2][0] == T_FUNCTION) {
                     $name = 'USE_FUNCTION';
-                    $text .= $tokens[$i+1][1] . $tokens[$i+2][1];
+                    $text .= $tokens[$i + 1][1] . $tokens[$i + 2][1];
                     $skip = 2;
                 }
 
@@ -188,7 +181,7 @@
 
             $this->tokens[] = new $tokenClass($text, $line, $this, $id++);
             $lines          = substr_count($text, "\n");
-            $line          += $lines;
+            $line += $lines;
 
             if ($tokenClass == 'PHP_Token_HALT_COMPILER') {
                 break;
@@ -212,7 +205,7 @@
     }
 
     /**
-     * @return integer
+     * @return int
      */
     public function count()
     {
@@ -271,7 +264,6 @@
 
     /**
      * @return array
-     * @since  Method available since Release 1.1.0
      */
     public function getTraits()
     {
@@ -296,19 +288,19 @@
      *
      * @param bool   $categorize OPTIONAL
      * @param string $category   OPTIONAL Either 'require_once', 'require',
-     *                                           'include_once', 'include'.
+     *                           'include_once', 'include'.
+     *
      * @return array
-     * @since  Method available since Release 1.1.0
      */
     public function getIncludes($categorize = false, $category = null)
     {
         if ($this->includes === null) {
-            $this->includes = array(
-              'require_once' => array(),
-              'require'      => array(),
-              'include_once' => array(),
-              'include'      => array()
-            );
+            $this->includes = [
+              'require_once' => [],
+              'require'      => [],
+              'include_once' => [],
+              'include'      => []
+            ];
 
             foreach ($this->tokens as $token) {
                 switch (get_class($token)) {
@@ -342,7 +334,6 @@
      * Returns the name of the function or method a line belongs to.
      *
      * @return string or null if the line is not in a function or method
-     * @since  Method available since Release 1.2.0
      */
     public function getFunctionForLine($line)
     {
@@ -355,12 +346,12 @@
 
     protected function parse()
     {
-        $this->interfaces = array();
-        $this->classes    = array();
-        $this->traits     = array();
-        $this->functions  = array();
-        $class            = array();
-        $classEndLine     = array();
+        $this->interfaces = [];
+        $this->classes    = [];
+        $this->traits     = [];
+        $this->functions  = [];
+        $class            = [];
+        $classEndLine     = [];
         $trait            = false;
         $traitEndLine     = false;
         $interface        = false;
@@ -375,8 +366,8 @@
                     $interface        = $token->getName();
                     $interfaceEndLine = $token->getEndLine();
 
-                    $this->interfaces[$interface] = array(
-                      'methods'   => array(),
+                    $this->interfaces[$interface] = [
+                      'methods'   => [],
                       'parent'    => $token->getParent(),
                       'keywords'  => $token->getKeywords(),
                       'docblock'  => $token->getDocblock(),
@@ -384,13 +375,13 @@
                       'endLine'   => $interfaceEndLine,
                       'package'   => $token->getPackage(),
                       'file'      => $this->filename
-                    );
+                    ];
                     break;
 
                 case 'PHP_Token_CLASS':
                 case 'PHP_Token_TRAIT':
-                    $tmp = array(
-                      'methods'   => array(),
+                    $tmp = [
+                      'methods'   => [],
                       'parent'    => $token->getParent(),
                       'interfaces'=> $token->getInterfaces(),
                       'keywords'  => $token->getKeywords(),
@@ -399,15 +390,13 @@
                       'endLine'   => $token->getEndLine(),
                       'package'   => $token->getPackage(),
                       'file'      => $this->filename
-                    );
+                    ];
 
                     if ($token instanceof PHP_Token_CLASS) {
                         $class[]        = $token->getName();
                         $classEndLine[] = $token->getEndLine();
 
-                        if ($class[count($class)-1] != 'anonymous class') {
-                            $this->classes[$class[count($class)-1]] = $tmp;
-                        }
+                        $this->classes[$class[count($class) - 1]] = $tmp;
                     } else {
                         $trait                = $token->getName();
                         $traitEndLine         = $token->getEndLine();
@@ -417,7 +406,7 @@
 
                 case 'PHP_Token_FUNCTION':
                     $name = $token->getName();
-                    $tmp  = array(
+                    $tmp  = [
                       'docblock'  => $token->getDocblock(),
                       'keywords'  => $token->getKeywords(),
                       'visibility'=> $token->getVisibility(),
@@ -426,7 +415,7 @@
                       'endLine'   => $token->getEndLine(),
                       'ccn'       => $token->getCCN(),
                       'file'      => $this->filename
-                    );
+                    ];
 
                     if (empty($class) &&
                         $trait === false &&
@@ -438,11 +427,11 @@
                             $tmp['startLine'],
                             $tmp['endLine']
                         );
-                    } elseif (!empty($class) && $class[count($class)-1] != 'anonymous class') {
-                        $this->classes[$class[count($class)-1]]['methods'][$name] = $tmp;
+                    } elseif (!empty($class)) {
+                        $this->classes[$class[count($class) - 1]]['methods'][$name] = $tmp;
 
                         $this->addFunctionToMap(
-                            $class[count($class)-1] . '::' . $name,
+                            $class[count($class) - 1] . '::' . $name,
                             $tmp['startLine'],
                             $tmp['endLine']
                         );
@@ -461,7 +450,7 @@
 
                 case 'PHP_Token_CLOSE_CURLY':
                     if (!empty($classEndLine) &&
-                        $classEndLine[count($classEndLine)-1] == $token->getLine()) {
+                        $classEndLine[count($classEndLine) - 1] == $token->getLine()) {
                         array_pop($classEndLine);
                         array_pop($class);
                     } elseif ($traitEndLine !== false &&
@@ -494,7 +483,7 @@
     }
 
     /**
-     * @return boolean
+     * @return bool
      */
     public function valid()
     {
@@ -502,7 +491,7 @@
     }
 
     /**
-     * @return integer
+     * @return int
      */
     public function key()
     {
@@ -525,8 +514,9 @@
     }
 
     /**
-     * @param  integer $offset
-     * @return boolean
+     * @param int $offset
+     *
+     * @return bool
      */
     public function offsetExists($offset)
     {
@@ -534,8 +524,10 @@
     }
 
     /**
-     * @param  integer $offset
+     * @param int $offset
+     *
      * @return mixed
+     *
      * @throws OutOfBoundsException
      */
     public function offsetGet($offset)
@@ -553,8 +545,8 @@
     }
 
     /**
-     * @param integer $offset
-     * @param mixed   $value
+     * @param int   $offset
+     * @param mixed $value
      */
     public function offsetSet($offset, $value)
     {
@@ -562,7 +554,8 @@
     }
 
     /**
-     * @param  integer $offset
+     * @param int $offset
+     *
      * @throws OutOfBoundsException
      */
     public function offsetUnset($offset)
@@ -582,7 +575,8 @@
     /**
      * Seek to an absolute position.
      *
-     * @param  integer $position
+     * @param int $position
+     *
      * @throws OutOfBoundsException
      */
     public function seek($position)
@@ -600,9 +594,9 @@
     }
 
     /**
-     * @param string  $name
-     * @param integer $startLine
-     * @param integer $endLine
+     * @param string $name
+     * @param int    $startLine
+     * @param int    $endLine
      */
     private function addFunctionToMap($name, $startLine, $endLine)
     {