Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@@ -13,6 +13,13 @@ use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
use function array_shift;
use function array_slice;
use function in_array;
use function is_array;
use function is_int;
use function is_string;
class TokenArrayScanner implements ScannerInterface
{
/**
@@ -23,27 +30,27 @@ class TokenArrayScanner implements ScannerInterface
/**
* @var array
*/
protected $tokens = array();
protected $tokens = [];
/**
* @var null
*/
protected $docComment = null;
protected $docComment;
/**
* @var NameInformation
*/
protected $nameInformation = null;
protected $nameInformation;
/**
* @var array
*/
protected $infos = array();
protected $infos = [];
/**
* @var AnnotationManager
*/
protected $annotationManager = null;
protected $annotationManager;
/**
* @param null|array $tokens
@@ -69,7 +76,7 @@ class TokenArrayScanner implements ScannerInterface
* @todo Assignment of $this->docComment should probably be done in scan()
* and then $this->getDocComment() just retrieves it.
*
* @return string
* @return string|null
*/
public function getDocComment()
{
@@ -96,7 +103,7 @@ class TokenArrayScanner implements ScannerInterface
{
$this->scan();
$namespaces = array();
$namespaces = [];
foreach ($this->infos as $info) {
if ($info['type'] == 'namespace') {
$namespaces[] = $info['namespace'];
@@ -118,7 +125,7 @@ class TokenArrayScanner implements ScannerInterface
}
/**
* @return array
* @return void
*/
public function getIncludes()
{
@@ -133,7 +140,7 @@ class TokenArrayScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'class') {
continue;
@@ -152,7 +159,7 @@ class TokenArrayScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'class') {
continue;
@@ -169,7 +176,7 @@ class TokenArrayScanner implements ScannerInterface
*
* @param string|int $name
* @throws Exception\InvalidArgumentException
* @return ClassScanner
* @return ClassScanner|false
*/
public function getClass($name)
{
@@ -189,7 +196,7 @@ class TokenArrayScanner implements ScannerInterface
}
}
if (!$classFound) {
if (! $classFound) {
return false;
}
}
@@ -198,7 +205,7 @@ class TokenArrayScanner implements ScannerInterface
array_slice(
$this->tokens,
$info['tokenStart'],
($info['tokenEnd'] - $info['tokenStart'] + 1)
$info['tokenEnd'] - $info['tokenStart'] + 1
), // zero indexed array
new NameInformation($info['namespace'], $info['uses'])
);
@@ -220,11 +227,11 @@ class TokenArrayScanner implements ScannerInterface
}
}
if (!$classFound) {
if (! $classFound) {
return false;
}
if (!isset($info)) {
if (! isset($info)) {
return;
}
@@ -237,7 +244,7 @@ class TokenArrayScanner implements ScannerInterface
public function getFunctionNames()
{
$this->scan();
$functionNames = array();
$functionNames = [];
foreach ($this->infos as $info) {
if ($info['type'] == 'function') {
$functionNames[] = $info['name'];
@@ -254,12 +261,12 @@ class TokenArrayScanner implements ScannerInterface
{
$this->scan();
$functions = array();
foreach ($this->infos as $info) {
if ($info['type'] == 'function') {
// @todo $functions[] = new FunctionScanner($info['name']);
}
}
$functions = [];
// foreach ($this->infos as $info) {
// if ($info['type'] == 'function') {
// // @todo $functions[] = new FunctionScanner($info['name']);
// }
// }
return $functions;
}
@@ -267,7 +274,7 @@ class TokenArrayScanner implements ScannerInterface
/**
* Export
*
* @param $tokens
* @param mixed $tokens
*/
public static function export($tokens)
{
@@ -294,21 +301,13 @@ class TokenArrayScanner implements ScannerInterface
return;
}
if (!$this->tokens) {
if (! $this->tokens) {
throw new Exception\RuntimeException('No tokens were provided');
}
/**
* Define PHP 5.4 'trait' token constant.
*/
if (!defined('T_TRAIT')) {
define('T_TRAIT', 42001);
}
/**
* Variables & Setup
*/
$tokens = &$this->tokens; // localize
$infos = &$this->infos; // localize
$tokenIndex = null;
@@ -323,9 +322,16 @@ class TokenArrayScanner implements ScannerInterface
/*
* MACRO creation
*/
$MACRO_TOKEN_ADVANCE = function () use (&$tokens, &$tokenIndex, &$token, &$tokenType, &$tokenContent, &$tokenLine) {
$tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1;
if (!isset($tokens[$tokenIndex])) {
$MACRO_TOKEN_ADVANCE = function () use (
&$tokens,
&$tokenIndex,
&$token,
&$tokenType,
&$tokenContent,
&$tokenLine
) {
$tokenIndex = $tokenIndex === null ? 0 : $tokenIndex + 1;
if (! isset($tokens[$tokenIndex])) {
$token = false;
$tokenContent = false;
$tokenType = false;
@@ -336,7 +342,7 @@ class TokenArrayScanner implements ScannerInterface
if (is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"') {
do {
$tokenIndex++;
} while (!(is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"'));
} while (! (is_string($tokens[$tokenIndex]) && $tokens[$tokenIndex] === '"'));
}
$token = $tokens[$tokenIndex];
if (is_array($token)) {
@@ -349,7 +355,7 @@ class TokenArrayScanner implements ScannerInterface
return $tokenIndex;
};
$MACRO_TOKEN_LOGICAL_START_INDEX = function () use (&$tokenIndex, &$docCommentIndex) {
return ($docCommentIndex === false) ? $tokenIndex : $docCommentIndex;
return $docCommentIndex === false ? $tokenIndex : $docCommentIndex;
};
$MACRO_DOC_COMMENT_START = function () use (&$tokenIndex, &$docCommentIndex) {
$docCommentIndex = $tokenIndex;
@@ -359,9 +365,9 @@ class TokenArrayScanner implements ScannerInterface
$MACRO_DOC_COMMENT_VALIDATE = function () use (&$tokenType, &$docCommentIndex) {
static $validTrailingTokens = null;
if ($validTrailingTokens === null) {
$validTrailingTokens = array(T_WHITESPACE, T_FINAL, T_ABSTRACT, T_INTERFACE, T_CLASS, T_FUNCTION);
$validTrailingTokens = [T_WHITESPACE, T_FINAL, T_ABSTRACT, T_INTERFACE, T_CLASS, T_FUNCTION];
}
if ($docCommentIndex !== false && !in_array($tokenType, $validTrailingTokens)) {
if ($docCommentIndex !== false && ! in_array($tokenType, $validTrailingTokens)) {
$docCommentIndex = false;
}
@@ -378,7 +384,6 @@ class TokenArrayScanner implements ScannerInterface
/**
* START FINITE STATE MACHINE FOR SCANNING TOKENS
*/
// Initialize token
$MACRO_TOKEN_ADVANCE();
@@ -392,23 +397,20 @@ class TokenArrayScanner implements ScannerInterface
$MACRO_DOC_COMMENT_VALIDATE();
switch ($tokenType) {
case T_DOC_COMMENT:
$MACRO_DOC_COMMENT_START();
goto SCANNER_CONTINUE;
//goto no break needed
// goto no break needed
case T_NAMESPACE:
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => 'namespace',
'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(),
'tokenEnd' => null,
'lineStart' => $token[2],
'lineEnd' => null,
'namespace' => null,
);
];
// start processing with next token
if ($MACRO_TOKEN_ADVANCE() === false) {
@@ -417,7 +419,7 @@ class TokenArrayScanner implements ScannerInterface
SCANNER_NAMESPACE_TOP:
if ($tokenType === null && $tokenContent === ';' || $tokenContent === '{') {
if (($tokenType === null && $tokenContent === ';') || $tokenContent === '{') {
goto SCANNER_NAMESPACE_END;
}
@@ -442,20 +444,23 @@ class TokenArrayScanner implements ScannerInterface
$MACRO_INFO_ADVANCE();
goto SCANNER_CONTINUE;
//goto no break needed
// goto no break needed
case T_USE:
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => 'use',
'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(),
'tokenEnd' => null,
'lineStart' => $tokens[$tokenIndex][2],
'lineEnd' => null,
'namespace' => $namespace,
'statements' => array(0 => array('use' => null,
'as' => null)),
);
'statements' => [
0 => [
'use' => null,
'as' => null,
],
],
];
$useStatementIndex = 0;
$useAsContext = false;
@@ -473,8 +478,10 @@ class TokenArrayScanner implements ScannerInterface
} elseif ($tokenContent === ',') {
$useAsContext = false;
$useStatementIndex++;
$infos[$infoIndex]['statements'][$useStatementIndex] = array('use' => null,
'as' => null);
$infos[$infoIndex]['statements'][$useStatementIndex] = [
'use' => null,
'as' => null,
];
}
}
@@ -505,22 +512,21 @@ class TokenArrayScanner implements ScannerInterface
$MACRO_INFO_ADVANCE();
goto SCANNER_CONTINUE;
//goto no break needed
// goto no break needed
case T_INCLUDE:
case T_INCLUDE_ONCE:
case T_REQUIRE:
case T_REQUIRE_ONCE:
// Static for performance
static $includeTypes = array(
static $includeTypes = [
T_INCLUDE => 'include',
T_INCLUDE_ONCE => 'include_once',
T_REQUIRE => 'require',
T_REQUIRE_ONCE => 'require_once'
);
T_REQUIRE_ONCE => 'require_once',
];
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => 'include',
'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(),
'tokenEnd' => null,
@@ -528,7 +534,7 @@ class TokenArrayScanner implements ScannerInterface
'lineEnd' => null,
'includeType' => $includeTypes[$tokens[$tokenIndex][0]],
'path' => '',
);
];
// start processing with next token
if ($MACRO_TOKEN_ADVANCE() === false) {
@@ -554,7 +560,7 @@ class TokenArrayScanner implements ScannerInterface
$MACRO_INFO_ADVANCE();
goto SCANNER_CONTINUE;
//goto no break needed
// goto no break needed
case T_FUNCTION:
case T_FINAL:
@@ -562,9 +568,8 @@ class TokenArrayScanner implements ScannerInterface
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
$infos[$infoIndex] = array(
'type' => ($tokenType === T_FUNCTION) ? 'function' : 'class',
$infos[$infoIndex] = [
'type' => $tokenType === T_FUNCTION ? 'function' : 'class',
'tokenStart' => $MACRO_TOKEN_LOGICAL_START_INDEX(),
'tokenEnd' => null,
'lineStart' => $tokens[$tokenIndex][2],
@@ -573,7 +578,7 @@ class TokenArrayScanner implements ScannerInterface
'uses' => $this->getUsesNoScan($namespace),
'name' => null,
'shortName' => null,
);
];
$classBraceCount = 0;
@@ -583,11 +588,18 @@ class TokenArrayScanner implements ScannerInterface
// process the name
if ($infos[$infoIndex]['shortName'] == ''
&& (($tokenType === T_CLASS || $tokenType === T_INTERFACE || $tokenType === T_TRAIT) && $infos[$infoIndex]['type'] === 'class'
&& (($tokenType === T_CLASS
|| $tokenType === T_INTERFACE
|| $tokenType === T_TRAIT)
&& $infos[$infoIndex]['type'] === 'class'
|| ($tokenType === T_FUNCTION && $infos[$infoIndex]['type'] === 'function'))
) {
$infos[$infoIndex]['shortName'] = $tokens[$tokenIndex + 2][1];
$infos[$infoIndex]['name'] = (($namespace !== null) ? $namespace . '\\' : '') . $infos[$infoIndex]['shortName'];
$infos[$infoIndex]['shortName'] = is_array($tokens[$tokenIndex + 2])
? $tokens[$tokenIndex + 2][1]
: $tokens[$tokenIndex + 2];
$infos[$infoIndex]['name'] = ($namespace !== null
? $namespace . '\\'
: '') . $infos[$infoIndex]['shortName'];
}
if ($tokenType === null) {
@@ -613,7 +625,7 @@ class TokenArrayScanner implements ScannerInterface
$MACRO_INFO_ADVANCE();
goto SCANNER_CONTINUE;
// goto no break needed
}
SCANNER_CONTINUE:
@@ -628,7 +640,6 @@ class TokenArrayScanner implements ScannerInterface
/**
* END FINITE STATE MACHINE FOR SCANNING TOKENS
*/
$this->isScanned = true;
}
@@ -657,7 +668,7 @@ class TokenArrayScanner implements ScannerInterface
*/
protected function getUsesNoScan($namespace)
{
$namespaces = array();
$namespaces = [];
foreach ($this->infos as $info) {
if ($info['type'] == 'namespace') {
$namespaces[] = $info['namespace'];
@@ -666,13 +677,13 @@ class TokenArrayScanner implements ScannerInterface
if ($namespace === null) {
$namespace = array_shift($namespaces);
} elseif (!is_string($namespace)) {
} elseif (! is_string($namespace)) {
throw new Exception\InvalidArgumentException('Invalid namespace provided');
} elseif (!in_array($namespace, $namespaces)) {
} elseif (! in_array($namespace, $namespaces)) {
return;
}
$uses = array();
$uses = [];
foreach ($this->infos as $info) {
if ($info['type'] !== 'use') {
continue;