Laravel version update
Laravel version update
This commit is contained in:
125
vendor/phpunit/php-token-stream/src/Token/Stream.php
vendored
125
vendor/phpunit/php-token-stream/src/Token/Stream.php
vendored
@@ -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 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
'^' => 'PHP_Token_CARET',
|
||||
'~' => 'PHP_Token_TILDE',
|
||||
'`' => 'PHP_Token_BACKTICK'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@@ -61,17 +55,17 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
/**
|
||||
* @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 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $lineToFunctionMap = array();
|
||||
protected $lineToFunctionMap = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -123,7 +117,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->tokens = array();
|
||||
$this->tokens = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +136,6 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since Method available since Release 1.1.0
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
@@ -157,6 +150,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
*/
|
||||
protected function scan($sourceCode)
|
||||
{
|
||||
$id = 0;
|
||||
$line = 1;
|
||||
$tokens = token_get_all($sourceCode);
|
||||
$numTokens = count($tokens);
|
||||
@@ -165,7 +159,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
for ($i = 0; $i < $numTokens; ++$i) {
|
||||
$token = $tokens[$i];
|
||||
unset($tokens[$i]);
|
||||
$skip = 0;
|
||||
|
||||
if (is_array($token)) {
|
||||
$name = substr(token_name($token[0]), 2);
|
||||
@@ -173,6 +167,10 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
if ($lastNonWhitespaceTokenWasDoubleColon && $name == 'CLASS') {
|
||||
$name = 'CLASS_NAME_CONSTANT';
|
||||
} 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];
|
||||
$skip = 2;
|
||||
}
|
||||
|
||||
$tokenClass = 'PHP_Token_' . $name;
|
||||
@@ -181,9 +179,9 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
$tokenClass = self::$customTokens[$token];
|
||||
}
|
||||
|
||||
$this->tokens[] = new $tokenClass($text, $line, $this, $i);
|
||||
$this->tokens[] = new $tokenClass($text, $line, $this, $id++);
|
||||
$lines = substr_count($text, "\n");
|
||||
$line += $lines;
|
||||
$line += $lines;
|
||||
|
||||
if ($tokenClass == 'PHP_Token_HALT_COMPILER') {
|
||||
break;
|
||||
@@ -197,6 +195,8 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
} elseif ($name != 'WHITESPACE') {
|
||||
$lastNonWhitespaceTokenWasDoubleColon = false;
|
||||
}
|
||||
|
||||
$i += $skip;
|
||||
}
|
||||
|
||||
$this->linesOfCode['loc'] = substr_count($sourceCode, "\n");
|
||||
@@ -205,7 +205,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
@@ -264,7 +264,6 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since Method available since Release 1.1.0
|
||||
*/
|
||||
public function getTraits()
|
||||
{
|
||||
@@ -289,19 +288,19 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
*
|
||||
* @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)) {
|
||||
@@ -335,7 +334,6 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
* 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)
|
||||
{
|
||||
@@ -348,12 +346,12 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
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;
|
||||
@@ -368,8 +366,8 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
$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(),
|
||||
@@ -377,13 +375,13 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
'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(),
|
||||
@@ -392,15 +390,13 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
'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();
|
||||
@@ -410,7 +406,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
case 'PHP_Token_FUNCTION':
|
||||
$name = $token->getName();
|
||||
$tmp = array(
|
||||
$tmp = [
|
||||
'docblock' => $token->getDocblock(),
|
||||
'keywords' => $token->getKeywords(),
|
||||
'visibility'=> $token->getVisibility(),
|
||||
@@ -419,7 +415,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
'endLine' => $token->getEndLine(),
|
||||
'ccn' => $token->getCCN(),
|
||||
'file' => $this->filename
|
||||
);
|
||||
];
|
||||
|
||||
if (empty($class) &&
|
||||
$trait === false &&
|
||||
@@ -431,11 +427,11 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
$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']
|
||||
);
|
||||
@@ -454,7 +450,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
|
||||
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 &&
|
||||
@@ -487,7 +483,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
@@ -495,7 +491,7 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
@@ -518,8 +514,9 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $offset
|
||||
* @return boolean
|
||||
* @param int $offset
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
@@ -527,8 +524,10 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $offset
|
||||
* @param int $offset
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws OutOfBoundsException
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
@@ -546,8 +545,8 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $offset
|
||||
* @param mixed $value
|
||||
* @param int $offset
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
@@ -555,7 +554,8 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $offset
|
||||
* @param int $offset
|
||||
*
|
||||
* @throws OutOfBoundsException
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
@@ -575,7 +575,8 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
/**
|
||||
* Seek to an absolute position.
|
||||
*
|
||||
* @param integer $position
|
||||
* @param int $position
|
||||
*
|
||||
* @throws OutOfBoundsException
|
||||
*/
|
||||
public function seek($position)
|
||||
@@ -593,9 +594,9 @@ class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param integer $startLine
|
||||
* @param integer $endLine
|
||||
* @param string $name
|
||||
* @param int $startLine
|
||||
* @param int $endLine
|
||||
*/
|
||||
private function addFunctionToMap($name, $startLine, $endLine)
|
||||
{
|
||||
|
@@ -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,22 +10,17 @@
|
||||
|
||||
/**
|
||||
* A caching factory for token stream objects.
|
||||
*
|
||||
* @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_CachingFactory
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $cache = array();
|
||||
protected static $cache = [];
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param string $filename
|
||||
*
|
||||
* @return PHP_Token_Stream
|
||||
*/
|
||||
public static function get($filename)
|
||||
@@ -45,7 +40,7 @@ class PHP_Token_Stream_CachingFactory
|
||||
if (is_string($filename)) {
|
||||
unset(self::$cache[$filename]);
|
||||
} else {
|
||||
self::$cache = array();
|
||||
self::$cache = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user