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
*/
@@ -27,18 +27,13 @@ class AggregateDirectoryScanner extends DirectoryScanner
// @todo
}
/*
public function getUses($returnScannerClass = false)
{}
*/
public function getIncludes($returnScannerClass = false)
{
}
public function getClasses($returnScannerClass = false, $returnDerivedScannerClass = false)
{
$classes = array();
$classes = [];
foreach ($this->directories as $scanner) {
$classes += $scanner->getClasses();
}
@@ -65,7 +60,7 @@ class AggregateDirectoryScanner extends DirectoryScanner
}
}
return (isset($scanner));
return isset($scanner);
}
/**
@@ -85,7 +80,7 @@ class AggregateDirectoryScanner extends DirectoryScanner
}
}
if (!isset($scanner)) {
if (! isset($scanner)) {
throw new Exception\RuntimeException('Class by that name was not found.');
}
@@ -101,8 +96,8 @@ class AggregateDirectoryScanner extends DirectoryScanner
{
$this->scan();
if (!$returnScannerClass) {
$functions = array();
if (! $returnScannerClass) {
$functions = [];
foreach ($this->infos as $info) {
if ($info['type'] == 'function') {
$functions[] = $info['name'];

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,18 @@ use Zend\Code\Annotation\AnnotationCollection;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\NameInformation;
use function array_pop;
use function current;
use function in_array;
use function is_string;
use function next;
use function preg_match;
use function reset;
use function strlen;
use function strpos;
use function substr;
use function substr_count;
class AnnotationScanner extends AnnotationCollection implements ScannerInterface
{
/**
@@ -23,22 +35,22 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
/**
* @var string
*/
protected $docComment = null;
protected $docComment;
/**
* @var NameInformation
*/
protected $nameInformation = null;
protected $nameInformation;
/**
* @var AnnotationManager
*/
protected $annotationManager = null;
protected $annotationManager;
/**
* @var array
*/
protected $annotations = array();
protected $annotations = [];
/**
* @param AnnotationManager $annotationManager
@@ -70,7 +82,7 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
*/
protected function scan(array $tokens)
{
$annotations = array();
$annotations = [];
$annotationIndex = -1;
$contentEnd = false;
@@ -80,28 +92,27 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
$token = current($tokens);
switch ($token[0]) {
case 'ANNOTATION_CLASS':
$contentEnd = false;
$annotationIndex++;
$class = substr($token[1], 1);
$class = $this->nameInformation->resolveName($class);
$annotations[$annotationIndex] = array($class, null);
$annotations[$annotationIndex] = [$class, null];
goto SCANNER_CONTINUE;
// goto no break needed
case 'ANNOTATION_CONTENT_START':
$annotations[$annotationIndex][1] = '';
//fall-through
// fall-through
case 'ANNOTATION_CONTENT_END':
case 'ANNOTATION_CONTENT':
case 'ANNOTATION_WHITESPACE':
case 'ANNOTATION_NEWLINE':
if (!$contentEnd && isset($annotations[$annotationIndex]) && is_string($annotations[$annotationIndex][1])) {
if (! $contentEnd
&& isset($annotations[$annotationIndex])
&& is_string($annotations[$annotationIndex][1])
) {
$annotations[$annotationIndex][1] .= $token[1];
}
@@ -110,6 +121,7 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
}
goto SCANNER_CONTINUE;
// goto no break needed
}
SCANNER_CONTINUE:
@@ -142,7 +154,7 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
$context = 0x00;
$stream = $this->docComment;
$streamIndex = null;
$tokens = array();
$tokens = [];
$tokenIndex = null;
$currentChar = null;
$currentWord = null;
@@ -150,21 +162,31 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
$annotationParentCount = 0;
$MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (&$stream, &$streamIndex, &$currentChar, &$currentWord, &$currentLine) {
$positionsForward = ($positionsForward > 0) ? $positionsForward : 1;
$streamIndex = ($streamIndex === null) ? 0 : $streamIndex + $positionsForward;
if (!isset($stream[$streamIndex])) {
$MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (
&$stream,
&$streamIndex,
&$currentChar,
&$currentWord,
&$currentLine
) {
$positionsForward = $positionsForward > 0 ? $positionsForward : 1;
$streamIndex = $streamIndex === null ? 0 : $streamIndex + $positionsForward;
if (! isset($stream[$streamIndex])) {
$currentChar = false;
return false;
}
$currentChar = $stream[$streamIndex];
$matches = array();
$currentLine = (preg_match('#(.*?)(?:\n|\r\n?)#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex);
$matches = [];
$currentLine = preg_match('#(.*?)(?:\n|\r\n?)#', $stream, $matches, null, $streamIndex) === 1
? $matches[1]
: substr($stream, $streamIndex);
if ($currentChar === ' ') {
$currentWord = (preg_match('#( +)#', $currentLine, $matches) === 1) ? $matches[1] : $currentLine;
$currentWord = preg_match('#( +)#', $currentLine, $matches) === 1 ? $matches[1] : $currentLine;
} else {
$currentWord = (($matches = strpos($currentLine, ' ')) !== false) ? substr($currentLine, 0, $matches) : $currentLine;
$currentWord = ($matches = strpos($currentLine, ' ')) !== false
? substr($currentLine, 0, $matches)
: $currentLine;
}
return $currentChar;
@@ -176,8 +198,8 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine));
};
$MACRO_TOKEN_ADVANCE = function () use (&$tokenIndex, &$tokens) {
$tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1;
$tokens[$tokenIndex] = array('ANNOTATION_UNKNOWN', '');
$tokenIndex = $tokenIndex === null ? 0 : $tokenIndex + 1;
$tokens[$tokenIndex] = ['ANNOTATION_UNKNOWN', ''];
};
$MACRO_TOKEN_SET_TYPE = function ($type) use (&$tokenIndex, &$tokens) {
$tokens[$tokenIndex][0] = $type;
@@ -192,7 +214,7 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
$tokens[$tokenIndex][1] .= $currentLine;
};
$MACRO_HAS_CONTEXT = function ($which) use (&$context) {
return (($context & $which) === $which);
return ($context & $which) === $which;
};
$MACRO_STREAM_ADVANCE_CHAR();
@@ -213,7 +235,7 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
}
if ($MACRO_HAS_CONTEXT($CONTEXT_CLASS)) {
if (in_array($currentChar, array(' ', '(', "\n", "\r"))) {
if (in_array($currentChar, [' ', '(', "\n", "\r"])) {
$context &= ~$CONTEXT_CLASS;
$MACRO_TOKEN_ADVANCE();
} else {
@@ -226,8 +248,8 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
}
// Since we don't know what line endings are used in the file, we check for all scenarios. If we find a
// cariage return (\r), we check the next character for a line feed (\n). If so we consume it and act as
// if the cariage return was a line feed.
// carriage return (\r), we check the next character for a line feed (\n). If so we consume it and act as
// if the carriage return was a line feed.
$lineEnded = $currentChar === "\n";
if ($currentChar === "\r") {
$lineEnded = true;
@@ -253,7 +275,11 @@ class AnnotationScanner extends AnnotationCollection implements ScannerInterface
}
if ($currentChar === ' ') {
$MACRO_TOKEN_SET_TYPE(($MACRO_HAS_CONTEXT($CONTEXT_ASTERISK)) ? 'ANNOTATION_WHITESPACE' : 'ANNOTATION_WHITESPACE_INDENT');
$MACRO_TOKEN_SET_TYPE(
$MACRO_HAS_CONTEXT($CONTEXT_ASTERISK)
? 'ANNOTATION_WHITESPACE'
: 'ANNOTATION_WHITESPACE_INDENT'
);
$MACRO_TOKEN_APPEND_WORD();
$MACRO_TOKEN_ADVANCE();
if ($MACRO_STREAM_ADVANCE_WORD() === false) {

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,17 +13,23 @@ use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
use function file_exists;
use function md5;
use function realpath;
use function spl_object_hash;
use function sprintf;
class CachingFileScanner extends FileScanner
{
/**
* @var array
*/
protected static $cache = array();
protected static $cache = [];
/**
* @var null|FileScanner
*/
protected $fileScanner = null;
protected $fileScanner;
/**
* @param string $file
@@ -32,7 +38,7 @@ class CachingFileScanner extends FileScanner
*/
public function __construct($file, AnnotationManager $annotationManager = null)
{
if (!file_exists($file)) {
if (! file_exists($file)) {
throw new Exception\InvalidArgumentException(sprintf(
'File "%s" not found',
$file
@@ -41,7 +47,9 @@ class CachingFileScanner extends FileScanner
$file = realpath($file);
$cacheId = md5($file) . '/' . ((isset($annotationManager) ? spl_object_hash($annotationManager) : 'no-annotation'));
$cacheId = md5($file) . '/' . (isset($annotationManager)
? spl_object_hash($annotationManager)
: 'no-annotation');
if (isset(static::$cache[$cacheId])) {
$this->fileScanner = static::$cache[$cacheId];
@@ -56,7 +64,7 @@ class CachingFileScanner extends FileScanner
*/
public static function clearCache()
{
static::$cache = array();
static::$cache = [];
}
/**

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
*/
@@ -14,6 +14,24 @@ use Zend\Code\Annotation;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
use function array_key_exists;
use function array_merge;
use function array_search;
use function array_slice;
use function array_values;
use function define;
use function defined;
use function explode;
use function in_array;
use function is_array;
use function is_int;
use function is_object;
use function is_string;
use function ltrim;
use function sprintf;
use function substr_count;
use function trigger_error;
class ClassScanner implements ScannerInterface
{
/**
@@ -24,27 +42,27 @@ class ClassScanner implements ScannerInterface
/**
* @var string
*/
protected $docComment = null;
protected $docComment;
/**
* @var string
*/
protected $name = null;
protected $name;
/**
* @var string
*/
protected $shortName = null;
protected $shortName;
/**
* @var int
*/
protected $lineStart = null;
protected $lineStart;
/**
* @var int
*/
protected $lineEnd = null;
protected $lineEnd;
/**
* @var bool
@@ -69,47 +87,47 @@ class ClassScanner implements ScannerInterface
/**
* @var string
*/
protected $parentClass = null;
protected $parentClass;
/**
* @var string
*/
protected $shortParentClass = null;
protected $shortParentClass;
/**
* @var array
*/
protected $interfaces = array();
protected $interfaces = [];
/**
* @var array
*/
protected $shortInterfaces = array();
protected $shortInterfaces = [];
/**
* @var array
*/
protected $tokens = array();
protected $tokens = [];
/**
* @var NameInformation
*/
protected $nameInformation = null;
protected $nameInformation;
/**
* @var array
*/
protected $infos = array();
protected $infos = [];
/**
* @var array
*/
protected $traits = array();
protected $traits = [];
/**
* @var array
*/
protected $methods = array();
protected $methods = [];
/**
* @param array $classTokens
@@ -156,7 +174,7 @@ class ClassScanner implements ScannerInterface
*/
public function getDocBlock()
{
if (!$docComment = $this->getDocComment()) {
if (! $docComment = $this->getDocComment()) {
return false;
}
@@ -220,6 +238,7 @@ class ClassScanner implements ScannerInterface
/**
* Verify if class is a trait
*
* @return bool
*/
public function isTrait()
@@ -236,7 +255,7 @@ class ClassScanner implements ScannerInterface
public function isInstantiable()
{
$this->scan();
return (!$this->isAbstract && !$this->isInterface);
return ! $this->isAbstract && ! $this->isInterface && ! $this->isTrait;
}
/**
@@ -269,7 +288,7 @@ class ClassScanner implements ScannerInterface
public function hasParentClass()
{
$this->scan();
return ($this->parentClass !== null);
return $this->parentClass !== null;
}
/**
@@ -303,7 +322,7 @@ class ClassScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'constant') {
continue;
@@ -330,7 +349,7 @@ class ClassScanner implements ScannerInterface
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'constant') {
continue;
@@ -366,7 +385,7 @@ class ClassScanner implements ScannerInterface
break;
}
}
if (!$constantFound) {
if (! $constantFound) {
return false;
}
} else {
@@ -374,7 +393,7 @@ class ClassScanner implements ScannerInterface
'Invalid constant name of info index type. Must be of type int or string'
);
}
if (!isset($info)) {
if (! isset($info)) {
return false;
}
$p = new ConstantScanner(
@@ -414,7 +433,7 @@ class ClassScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'property') {
continue;
@@ -435,7 +454,7 @@ class ClassScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'property') {
continue;
@@ -471,7 +490,7 @@ class ClassScanner implements ScannerInterface
break;
}
}
if (!$propertyFound) {
if (! $propertyFound) {
return false;
}
} else {
@@ -479,7 +498,7 @@ class ClassScanner implements ScannerInterface
'Invalid property name of info index type. Must be of type int or string'
);
}
if (!isset($info)) {
if (! isset($info)) {
return false;
}
$p = new PropertyScanner(
@@ -547,7 +566,9 @@ class ClassScanner implements ScannerInterface
*/
public function getTraitNames()
{
$return = array();
$this->scan();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] !== 'use') {
continue;
@@ -562,7 +583,6 @@ class ClassScanner implements ScannerInterface
$return[] = $traitName;
}
}
break;
}
return $return;
@@ -575,7 +595,9 @@ class ClassScanner implements ScannerInterface
*/
public function getTraitAliases()
{
$return = array();
$this->scan();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] !== 'use') {
continue;
@@ -598,7 +620,6 @@ class ClassScanner implements ScannerInterface
$return[$alias['alias']] = $trait . '::' . $method;
}
}
break;
}
return $return;
@@ -612,6 +633,8 @@ class ClassScanner implements ScannerInterface
*/
protected function getVisibilityForAlias($aliasName)
{
$this->scan();
$return = null;
foreach ($this->infos as $info) {
if ($info['type'] !== 'use') {
@@ -632,7 +655,6 @@ class ClassScanner implements ScannerInterface
}
}
}
break;
}
return $return;
@@ -645,7 +667,9 @@ class ClassScanner implements ScannerInterface
*/
protected function getBlockedTraitMethods()
{
$return = array();
$this->scan();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] !== 'use') {
continue;
@@ -668,7 +692,6 @@ class ClassScanner implements ScannerInterface
$return[] = $trait . '::' . $method;
}
}
break;
}
return $return;
@@ -684,7 +707,7 @@ class ClassScanner implements ScannerInterface
$this->scan();
$methods = $this->getMethods();
$return = array();
$return = [];
foreach ($methods as $method) {
$return[] = $method->getName();
}
@@ -711,8 +734,8 @@ class ClassScanner implements ScannerInterface
}
// Merge in trait methods
if ($info['type'] === "use") {
$traitMethods = array();
if ($info['type'] === 'use') {
$traitMethods = [];
$traits = $this->getTraits();
$insteadof = $this->getBlockedTraitMethods();
$aliases = $this->getTraitAliases();
@@ -845,14 +868,13 @@ class ClassScanner implements ScannerInterface
return;
}
if (!$this->tokens) {
if (! $this->tokens) {
throw new Exception\RuntimeException('No tokens were provided');
}
/**
* Variables & Setup
*/
$tokens = &$this->tokens; // localize
$infos = &$this->infos; // localize
$tokenIndex = null;
@@ -876,8 +898,8 @@ class ClassScanner implements ScannerInterface
&$tokenLine
) {
static $lastTokenArray = null;
$tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1;
if (!isset($tokens[$tokenIndex])) {
$tokenIndex = $tokenIndex === null ? 0 : $tokenIndex + 1;
if (! isset($tokens[$tokenIndex])) {
$token = false;
$tokenContent = false;
$tokenType = false;
@@ -890,13 +912,13 @@ class ClassScanner implements ScannerInterface
if (is_string($token)) {
$tokenType = null;
$tokenContent = $token;
$tokenLine = $tokenLine + substr_count(
$lastTokenArray[1],
$tokenLine += substr_count(
$lastTokenArray[1] ?? '',
"\n"
); // adjust token line by last known newline count
} else {
$lastTokenArray = $token;
list($tokenType, $tokenContent, $tokenLine) = $token;
[$tokenType, $tokenContent, $tokenLine] = $token;
}
return $tokenIndex;
@@ -912,16 +934,13 @@ class ClassScanner implements ScannerInterface
/**
* START FINITE STATE MACHINE FOR SCANNING TOKENS
*/
// Initialize token
$MACRO_TOKEN_ADVANCE();
SCANNER_TOP:
switch ($tokenType) {
case T_DOC_COMMENT:
$this->docComment = $tokenContent;
goto SCANNER_CONTINUE;
//goto no break needed
@@ -931,7 +950,6 @@ class ClassScanner implements ScannerInterface
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:
// CLASS INFORMATION
$classContext = null;
@@ -946,7 +964,6 @@ class ClassScanner implements ScannerInterface
$this->lineStart = $tokenLine;
switch ($tokenType) {
case T_FINAL:
$this->isFinal = true;
goto SCANNER_CLASS_INFO_CONTINUE;
@@ -966,10 +983,11 @@ class ClassScanner implements ScannerInterface
$this->name = $this->shortName;
}
goto SCANNER_CLASS_INFO_CONTINUE;
// goto no break needed
case T_INTERFACE:
$this->isInterface = true;
//fall-through
// fall-through
case T_CLASS:
$this->shortName = $tokens[$tokenIndex + 2][1];
if ($this->nameInformation && $this->nameInformation->hasNamespace()) {
@@ -978,38 +996,43 @@ class ClassScanner implements ScannerInterface
$this->name = $this->shortName;
}
goto SCANNER_CLASS_INFO_CONTINUE;
//goto no break needed
// goto no break needed
case T_NS_SEPARATOR:
case T_STRING:
switch ($classContext) {
case T_EXTENDS:
$this->shortParentClass .= $tokenContent;
if ($this->isInterface) {
$this->shortInterfaces[$classInterfaceIndex] .= $tokenContent;
} else {
$this->shortParentClass .= $tokenContent;
}
break;
case T_IMPLEMENTS:
$this->shortInterfaces[$classInterfaceIndex] .= $tokenContent;
break;
}
goto SCANNER_CLASS_INFO_CONTINUE;
//goto no break needed
// goto no break needed
case T_EXTENDS:
case T_IMPLEMENTS:
$classContext = $tokenType;
if (($this->isInterface && $classContext === T_EXTENDS) || $classContext === T_IMPLEMENTS) {
$this->shortInterfaces[$classInterfaceIndex] = '';
} elseif (!$this->isInterface && $classContext === T_EXTENDS) {
} elseif (! $this->isInterface && $classContext === T_EXTENDS) {
$this->shortParentClass = '';
}
goto SCANNER_CLASS_INFO_CONTINUE;
//goto no break needed
// goto no break needed
case null:
if ($classContext == T_IMPLEMENTS && $tokenContent == ',') {
if (($classContext == T_IMPLEMENTS && $tokenContent == ',')
|| ($classContext == T_EXTENDS && $tokenContent == ',' && $this->isInterface)
) {
$classInterfaceIndex++;
$this->shortInterfaces[$classInterfaceIndex] = '';
}
}
SCANNER_CLASS_INFO_CONTINUE:
@@ -1022,7 +1045,6 @@ class ClassScanner implements ScannerInterface
SCANNER_CLASS_INFO_END:
goto SCANNER_CONTINUE;
}
if ($tokenType === null && $tokenContent === '{' && $braceCount === 0) {
@@ -1038,10 +1060,8 @@ class ClassScanner implements ScannerInterface
}
switch ($tokenType) {
case T_CONST:
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => 'constant',
'tokenStart' => $tokenIndex,
'tokenEnd' => null,
@@ -1049,7 +1069,7 @@ class ClassScanner implements ScannerInterface
'lineEnd' => null,
'name' => null,
'value' => null,
);
];
SCANNER_CLASS_BODY_CONST_TOP:
@@ -1080,21 +1100,21 @@ class ClassScanner implements ScannerInterface
define('T_INSTEADOF', 24000);
}
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => 'use',
'tokenStart' => $tokenIndex,
'tokenEnd' => null,
'lineStart' => $tokens[$tokenIndex][2],
'lineEnd' => null,
'name' => $namespace,
'use_statements' => array(0 => null),
'aliases' => array(0 => null),
);
'use_statements' => [0 => null],
'aliases' => [0 => null],
];
$isOriginalName = array(T_STRING, T_DOUBLE_COLON);
$isAlias = array(T_STRING);
$isVisibility = array(T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC);
$isAliasType = array(T_AS, T_INSTEADOF);
$isOriginalName = [T_STRING, T_DOUBLE_COLON];
$isAlias = [T_STRING];
$isVisibility = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC];
$isAliasType = [T_AS, T_INSTEADOF];
$isValidAlias = array_merge($isOriginalName, $isAlias, $isVisibility, $isAliasType);
$useStatementIndex = 0;
@@ -1110,16 +1130,16 @@ class ClassScanner implements ScannerInterface
SCANNER_USE_TOP:
if ($tokenType === null) {
if ($tokenContent === "{") {
if ($tokenContent === '{') {
$useStatementIndex = 0;
$useAliasContext = true;
$infos[$infoIndex]['aliases'][$useStatementIndex] = array(
$infos[$infoIndex]['aliases'][$useStatementIndex] = [
'original' => null,
'alias' => null,
'visibility' => null,
'type' => 'as'
);
} elseif ($tokenContent === "}") {
'type' => 'as',
];
} elseif ($tokenContent === '}') {
$useAliasContext = false;
goto SCANNER_USE_END;
} elseif ($tokenContent === ';') {
@@ -1148,17 +1168,17 @@ class ClassScanner implements ScannerInterface
if (in_array($tokenType, $isValidAlias)
&& empty($infos[$infoIndex]['aliases'][$useStatementIndex])
) {
$infos[$infoIndex]['aliases'][$useStatementIndex] = array(
$infos[$infoIndex]['aliases'][$useStatementIndex] = [
'original' => null,
'visibility' => null,
'alias' => null,
'type' => null
);
'type' => null,
];
}
if ($tokenType == T_AS || $tokenType == T_INSTEADOF) {
$useAsContext = true;
$infos[$infoIndex]['aliases'][$useStatementIndex]['type'] = ($tokenType == T_INSTEADOF)
$infos[$infoIndex]['aliases'][$useStatementIndex]['type'] = $tokenType == T_INSTEADOF
? 'insteadof'
: 'as';
goto SCANNER_USE_CONTINUE;
@@ -1187,6 +1207,7 @@ class ClassScanner implements ScannerInterface
$MACRO_INFO_ADVANCE();
goto SCANNER_CLASS_BODY_CONTINUE;
// goto no break needed
case T_DOC_COMMENT:
case T_PUBLIC:
@@ -1196,15 +1217,14 @@ class ClassScanner implements ScannerInterface
case T_FINAL:
case T_VAR:
case T_FUNCTION:
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => null,
'tokenStart' => $tokenIndex,
'tokenEnd' => null,
'lineStart' => $tokenLine,
'lineEnd' => null,
'name' => null,
);
];
$memberContext = null;
$methodBodyStarted = false;
@@ -1218,19 +1238,21 @@ class ClassScanner implements ScannerInterface
$braceCount++;
goto SCANNER_CLASS_BODY_MEMBER_CONTINUE;
// goto no break needed
case '}':
$braceCount--;
goto SCANNER_CLASS_BODY_MEMBER_CONTINUE;
// goto no break needed
case ';':
$infos[$infoIndex]['tokenEnd'] = $tokenIndex;
goto SCANNER_CLASS_BODY_MEMBER_CONTINUE;
// goto no break needed
}
}
if ($memberContext !== null) {
if (
($memberContext === 'property' && $tokenContent === ';')
if (($memberContext === 'property' && $tokenContent === ';')
|| ($memberContext === 'method' && $methodBodyStarted && $braceCount === 1)
|| ($memberContext === 'method' && $this->isInterface && $tokenContent === ';')
) {
@@ -1239,7 +1261,6 @@ class ClassScanner implements ScannerInterface
}
switch ($tokenType) {
case T_CONST:
$memberContext = 'constant';
$infos[$infoIndex]['type'] = 'constant';
@@ -1284,7 +1305,6 @@ class ClassScanner implements ScannerInterface
// goto no break needed
case null: // no type, is a string
switch ($tokenContent) {
case '{':
$braceCount++;
@@ -1294,6 +1314,7 @@ class ClassScanner implements ScannerInterface
case '}':
$braceCount--;
goto SCANNER_CLASS_BODY_CONTINUE;
// goto no break needed
}
}
@@ -1338,7 +1359,5 @@ class ClassScanner implements ScannerInterface
}
$this->isScanned = true;
return;
}
}

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,15 @@ use Zend\Code\Annotation;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
use function current;
use function is_string;
use function next;
use function reset;
use function strtolower;
use function substr;
use function strpos;
use function var_export;
class ConstantScanner implements ScannerInterface
{
/**
@@ -156,7 +165,7 @@ class ConstantScanner implements ScannerInterface
return;
}
if (!$this->tokens) {
if (! $this->tokens) {
throw new Exception\RuntimeException('No tokens were provided');
}
@@ -171,7 +180,7 @@ class ConstantScanner implements ScannerInterface
$token = current($tokens);
if (!is_string($token)) {
if (! is_string($token)) {
list($tokenType, $tokenContent, $tokenLine) = $token;
switch ($tokenType) {
@@ -183,7 +192,7 @@ class ConstantScanner implements ScannerInterface
// fall-through
case T_STRING:
$string = (is_string($token)) ? $token : $tokenContent;
$string = is_string($token) ? $token : $tokenContent;
if (null === $this->name) {
$this->name = $string;
@@ -207,9 +216,9 @@ class ConstantScanner implements ScannerInterface
case T_CONSTANT_ENCAPSED_STRING:
case T_DNUMBER:
case T_LNUMBER:
$string = (is_string($token)) ? $token : $tokenContent;
$string = is_string($token) ? $token : $tokenContent;
if (substr($string, 0, 1) === '"' || substr($string, 0, 1) === "'") {
if (0 === strpos($string, '"') || 0 === strpos($string, "'")) {
$this->value = substr($string, 1, -1); // Remove quotes
} else {
$this->value = $string;

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
*/
@@ -11,27 +11,32 @@ namespace Zend\Code\Scanner;
use Zend\Code\Exception;
use function array_keys;
use function array_merge;
use function sprintf;
use function trigger_error;
class DerivedClassScanner extends ClassScanner
{
/**
* @var DirectoryScanner
*/
protected $directoryScanner = null;
protected $directoryScanner;
/**
* @var ClassScanner
*/
protected $classScanner = null;
protected $classScanner;
/**
* @var array
*/
protected $parentClassScanners = array();
protected $parentClassScanners = [];
/**
* @var array
*/
protected $interfaceClassScanners = array();
protected $interfaceClassScanners = [];
/**
* @param ClassScanner $classScanner
@@ -47,9 +52,9 @@ class DerivedClassScanner extends ClassScanner
while ($currentScannerClass && $currentScannerClass->hasParentClass()) {
$currentParentClassName = $currentScannerClass->getParentClass();
if ($directoryScanner->hasClass($currentParentClassName)) {
$currentParentClass = $directoryScanner->getClass($currentParentClassName);
$currentParentClass = $directoryScanner->getClass($currentParentClassName);
$this->parentClassScanners[$currentParentClassName] = $currentParentClass;
$currentScannerClass = $currentParentClass;
$currentScannerClass = $currentParentClass;
} else {
$currentScannerClass = false;
}
@@ -123,7 +128,7 @@ class DerivedClassScanner extends ClassScanner
*/
public function hasParentClass()
{
return ($this->classScanner->getParentClass() !== null);
return $this->classScanner->getParentClass() !== null;
}
/**

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,15 @@ use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Zend\Code\Exception;
use function array_keys;
use function array_merge;
use function is_array;
use function is_dir;
use function is_string;
use function pathinfo;
use function realpath;
use function sprintf;
class DirectoryScanner implements ScannerInterface
{
/**
@@ -23,17 +32,17 @@ class DirectoryScanner implements ScannerInterface
/**
* @var string[]|DirectoryScanner[]
*/
protected $directories = array();
protected $directories = [];
/**
* @var FileScanner[]
*/
protected $fileScanners = array();
protected $fileScanners = [];
/**
* @var array
*/
protected $classToFileScanner = null;
protected $classToFileScanner;
/**
* @param null|string|array $directory
@@ -62,7 +71,7 @@ class DirectoryScanner implements ScannerInterface
$this->directories[] = $directory;
} elseif (is_string($directory)) {
$realDir = realpath($directory);
if (!$realDir || !is_dir($realDir)) {
if (! $realDir || ! is_dir($realDir)) {
throw new Exception\InvalidArgumentException(sprintf(
'Directory "%s" does not exist',
$realDir
@@ -139,9 +148,9 @@ class DirectoryScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->fileScanners as $fileScanner) {
$return[] = ($returnFileScanners) ? $fileScanner : $fileScanner->getFile();
$return[] = $returnFileScanners ? $fileScanner : $fileScanner->getFile();
}
return $return;
@@ -173,7 +182,7 @@ class DirectoryScanner implements ScannerInterface
$this->createClassToFileScannerCache();
}
$returnClasses = array();
$returnClasses = [];
foreach ($this->classToFileScanner as $className => $fsIndex) {
$classScanner = $this->fileScanners[$fsIndex]->getClass($className);
if ($returnDerivedScannerClass) {
@@ -197,7 +206,7 @@ class DirectoryScanner implements ScannerInterface
$this->createClassToFileScannerCache();
}
return (isset($this->classToFileScanner[$class]));
return isset($this->classToFileScanner[$class]);
}
/**
@@ -214,7 +223,7 @@ class DirectoryScanner implements ScannerInterface
$this->createClassToFileScannerCache();
}
if (!isset($this->classToFileScanner[$class])) {
if (! isset($this->classToFileScanner[$class])) {
throw new Exception\InvalidArgumentException('Class not found.');
}
@@ -222,7 +231,7 @@ class DirectoryScanner implements ScannerInterface
$fs = $this->fileScanners[$this->classToFileScanner[$class]];
$returnClass = $fs->getClass($class);
if (($returnClass instanceof ClassScanner) && $returnDerivedScannerClass) {
if ($returnClass instanceof ClassScanner && $returnDerivedScannerClass) {
return new DerivedClassScanner($returnClass, $this);
}
@@ -240,7 +249,8 @@ class DirectoryScanner implements ScannerInterface
return;
}
$this->classToFileScanner = array();
$this->classToFileScanner = [];
/** @var FileScanner $fileScanner */
foreach ($this->fileScanners as $fsIndex => $fileScanner) {
$fsClasses = $fileScanner->getClassNames();

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
*/
@@ -12,6 +12,19 @@ namespace Zend\Code\Scanner;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\NameInformation;
use function array_pop;
use function array_push;
use function current;
use function end;
use function key;
use function next;
use function preg_match;
use function reset;
use function strlen;
use function strpos;
use function substr;
use function trim;
class DocBlockScanner implements ScannerInterface
{
/**
@@ -22,22 +35,22 @@ class DocBlockScanner implements ScannerInterface
/**
* @var string
*/
protected $docComment = null;
protected $docComment;
/**
* @var NameInformation
*/
protected $nameInformation = null;
protected $nameInformation;
/**
* @var AnnotationManager
*/
protected $annotationManager = null;
protected $annotationManager;
/**
* @var string
*/
protected $shortDescription = null;
protected $shortDescription;
/**
* @var string
@@ -47,12 +60,12 @@ class DocBlockScanner implements ScannerInterface
/**
* @var array
*/
protected $tags = array();
protected $tags = [];
/**
* @var array
*/
protected $annotations = array();
protected $annotations = [];
/**
* @param string $docComment
@@ -135,7 +148,9 @@ class DocBlockScanner implements ScannerInterface
case 'DOCBLOCK_WHITESPACE':
case 'DOCBLOCK_TEXT':
if ($tagIndex !== null) {
$this->tags[$tagIndex]['value'] .= ($this->tags[$tagIndex]['value'] == '') ? $token[1] : ' ' . $token[1];
$this->tags[$tagIndex]['value'] .= $this->tags[$tagIndex]['value'] == ''
? $token[1]
: ' ' . $token[1];
goto SCANNER_CONTINUE;
} elseif ($mode <= 2) {
if ($mode == 1) {
@@ -147,8 +162,10 @@ class DocBlockScanner implements ScannerInterface
}
//gotos no break needed
case 'DOCBLOCK_TAG':
array_push($this->tags, array('name' => $token[1],
'value' => ''));
array_push($this->tags, [
'name' => $token[1],
'value' => '',
]);
end($this->tags);
$tagIndex = key($this->tags);
$mode = 3;
@@ -157,7 +174,6 @@ class DocBlockScanner implements ScannerInterface
case 'DOCBLOCK_COMMENTEND':
goto SCANNER_END;
}
SCANNER_CONTINUE:
@@ -184,27 +200,37 @@ class DocBlockScanner implements ScannerInterface
$context = 0x00;
$stream = $this->docComment;
$streamIndex = null;
$tokens = array();
$tokens = [];
$tokenIndex = null;
$currentChar = null;
$currentWord = null;
$currentLine = null;
$MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (&$stream, &$streamIndex, &$currentChar, &$currentWord, &$currentLine) {
$positionsForward = ($positionsForward > 0) ? $positionsForward : 1;
$streamIndex = ($streamIndex === null) ? 0 : $streamIndex + $positionsForward;
if (!isset($stream[$streamIndex])) {
$MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (
&$stream,
&$streamIndex,
&$currentChar,
&$currentWord,
&$currentLine
) {
$positionsForward = $positionsForward > 0 ? $positionsForward : 1;
$streamIndex = $streamIndex === null ? 0 : $streamIndex + $positionsForward;
if (! isset($stream[$streamIndex])) {
$currentChar = false;
return false;
}
$currentChar = $stream[$streamIndex];
$matches = array();
$currentLine = (preg_match('#(.*?)\r?\n#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex);
$matches = [];
$currentLine = preg_match('#(.*?)\r?\n#', $stream, $matches, null, $streamIndex) === 1
? $matches[1]
: substr($stream, $streamIndex);
if ($currentChar === ' ') {
$currentWord = (preg_match('#( +)#', $currentLine, $matches) === 1) ? $matches[1] : $currentLine;
$currentWord = preg_match('#( +)#', $currentLine, $matches) === 1 ? $matches[1] : $currentLine;
} else {
$currentWord = (($matches = strpos($currentLine, ' ')) !== false) ? substr($currentLine, 0, $matches) : $currentLine;
$currentWord = ($matches = strpos($currentLine, ' ')) !== false
? substr($currentLine, 0, $matches)
: $currentLine;
}
return $currentChar;
@@ -216,8 +242,8 @@ class DocBlockScanner implements ScannerInterface
return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine));
};
$MACRO_TOKEN_ADVANCE = function () use (&$tokenIndex, &$tokens) {
$tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1;
$tokens[$tokenIndex] = array('DOCBLOCK_UNKNOWN', '');
$tokenIndex = $tokenIndex === null ? 0 : $tokenIndex + 1;
$tokens[$tokenIndex] = ['DOCBLOCK_UNKNOWN', ''];
};
$MACRO_TOKEN_SET_TYPE = function ($type) use (&$tokenIndex, &$tokens) {
$tokens[$tokenIndex][0] = $type;
@@ -264,7 +290,11 @@ class DocBlockScanner implements ScannerInterface
}
if ($currentChar === ' ' || $currentChar === "\t") {
$MACRO_TOKEN_SET_TYPE(($context & $CONTEXT_INSIDE_ASTERISK) ? 'DOCBLOCK_WHITESPACE' : 'DOCBLOCK_WHITESPACE_INDENT');
$MACRO_TOKEN_SET_TYPE(
$context & $CONTEXT_INSIDE_ASTERISK
? 'DOCBLOCK_WHITESPACE'
: 'DOCBLOCK_WHITESPACE_INDENT'
);
$MACRO_TOKEN_APPEND_WORD();
$MACRO_TOKEN_ADVANCE();
if ($MACRO_STREAM_ADVANCE_WORD() === false) {

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
*/
@@ -12,12 +12,17 @@ namespace Zend\Code\Scanner;
use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;
use function file_exists;
use function file_get_contents;
use function sprintf;
use function token_get_all;
class FileScanner extends TokenArrayScanner implements ScannerInterface
{
/**
* @var string
*/
protected $file = null;
protected $file;
/**
* @param string $file
@@ -27,7 +32,7 @@ class FileScanner extends TokenArrayScanner implements ScannerInterface
public function __construct($file, AnnotationManager $annotationManager = null)
{
$this->file = $file;
if (!file_exists($file)) {
if (! file_exists($file)) {
throw new Exception\InvalidArgumentException(sprintf(
'File "%s" not found',
$file

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
*/

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,42 +13,51 @@ use Zend\Code\Annotation\AnnotationManager;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
use function array_slice;
use function count;
use function is_int;
use function is_string;
use function ltrim;
use function strtolower;
use function substr_count;
use function var_export;
class MethodScanner implements ScannerInterface
{
/**
* @var bool
*/
protected $isScanned = false;
protected $isScanned = false;
/**
* @var string
*/
protected $docComment = null;
protected $docComment;
/**
* @var ClassScanner
*/
protected $scannerClass = null;
protected $scannerClass;
/**
* @var string
*/
protected $class = null;
protected $class;
/**
* @var string
*/
protected $name = null;
protected $name;
/**
* @var int
*/
protected $lineStart = null;
protected $lineStart;
/**
* @var int
*/
protected $lineEnd = null;
protected $lineEnd;
/**
* @var bool
@@ -88,17 +97,17 @@ class MethodScanner implements ScannerInterface
/**
* @var array
*/
protected $tokens = array();
protected $tokens = [];
/**
* @var NameInformation
*/
protected $nameInformation = null;
protected $nameInformation;
/**
* @var array
*/
protected $infos = array();
protected $infos = [];
/**
* @param array $methodTokens
@@ -131,7 +140,7 @@ class MethodScanner implements ScannerInterface
}
/**
* @return MethodScanner
* @return ClassScanner
*/
public function getClassScanner()
{
@@ -180,7 +189,7 @@ class MethodScanner implements ScannerInterface
/**
* @param AnnotationManager $annotationManager
* @return AnnotationScanner
* @return AnnotationScanner|false
*/
public function getAnnotations(AnnotationManager $annotationManager)
{
@@ -255,7 +264,7 @@ class MethodScanner implements ScannerInterface
* Override the given name for a method, this is necessary to
* support traits.
*
* @param $name
* @param string $name
* @return self
*/
public function setName($name)
@@ -268,13 +277,13 @@ class MethodScanner implements ScannerInterface
* Visibility must be of T_PUBLIC, T_PRIVATE or T_PROTECTED
* Needed to support traits
*
* @param $visibility T_PUBLIC | T_PRIVATE | T_PROTECTED
* @param int $visibility T_PUBLIC | T_PRIVATE | T_PROTECTED
* @return self
* @throws \Zend\Code\Exception
* @throws \Zend\Code\Exception\InvalidArgumentException
*/
public function setVisibility($visibility)
{
switch (strtolower($visibility)) {
switch ($visibility) {
case T_PUBLIC:
$this->isPublic = true;
$this->isPrivate = false;
@@ -294,7 +303,7 @@ class MethodScanner implements ScannerInterface
break;
default:
throw new Exception("Invalid visibility argument passed to setVisibility.");
throw new Exception\InvalidArgumentException('Invalid visibility argument passed to setVisibility.');
}
return $this;
@@ -316,14 +325,14 @@ class MethodScanner implements ScannerInterface
{
$this->scan();
$return = array();
$return = [];
foreach ($this->infos as $info) {
if ($info['type'] != 'parameter') {
continue;
}
if (!$returnScanner) {
if (! $returnScanner) {
$return[] = $info['name'];
} else {
$return[] = $this->getParameter($info['name']);
@@ -354,7 +363,7 @@ class MethodScanner implements ScannerInterface
}
unset($info);
}
if (!isset($info)) {
if (! isset($info)) {
throw new Exception\InvalidArgumentException('Index of info offset is not about a parameter');
}
}
@@ -400,14 +409,13 @@ class MethodScanner implements ScannerInterface
return;
}
if (!$this->tokens) {
if (! $this->tokens) {
throw new Exception\RuntimeException('No tokens were provided');
}
/**
* Variables & Setup
*/
$tokens = &$this->tokens; // localize
$infos = &$this->infos; // localize
$tokenIndex = null;
@@ -430,8 +438,8 @@ class MethodScanner implements ScannerInterface
&$tokenLine
) {
static $lastTokenArray = null;
$tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1;
if (!isset($tokens[$tokenIndex])) {
$tokenIndex = $tokenIndex === null ? 0 : $tokenIndex + 1;
if (! isset($tokens[$tokenIndex])) {
$token = false;
$tokenContent = false;
$tokenType = false;
@@ -443,18 +451,19 @@ class MethodScanner implements ScannerInterface
if (is_string($token)) {
$tokenType = null;
$tokenContent = $token;
$tokenLine = $tokenLine + substr_count(
$lastTokenArray[1],
$tokenLine += substr_count(
$lastTokenArray[1] ?? '',
"\n"
); // adjust token line by last known newline count
} else {
list($tokenType, $tokenContent, $tokenLine) = $token;
$lastTokenArray = $token;
[$tokenType, $tokenContent, $tokenLine] = $token;
}
return $tokenIndex;
};
$MACRO_INFO_START = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) {
$infos[$infoIndex] = array(
$infos[$infoIndex] = [
'type' => 'parameter',
'tokenStart' => $tokenIndex,
'tokenEnd' => null,
@@ -462,7 +471,7 @@ class MethodScanner implements ScannerInterface
'lineEnd' => $tokenLine,
'name' => null,
'position' => $infoIndex + 1, // position is +1 of infoIndex
);
];
};
$MACRO_INFO_ADVANCE = function () use (&$infoIndex, &$infos, &$tokenIndex, &$tokenLine) {
$infos[$infoIndex]['tokenEnd'] = $tokenIndex;
@@ -475,13 +484,12 @@ class MethodScanner implements ScannerInterface
/**
* START FINITE STATE MACHINE FOR SCANNING TOKENS
*/
// Initialize token
$MACRO_TOKEN_ADVANCE();
SCANNER_TOP:
$this->lineStart = ($this->lineStart) ? : $tokenLine;
$this->lineStart = $this->lineStart ? : $tokenLine;
switch ($tokenType) {
case T_DOC_COMMENT:
@@ -490,47 +498,53 @@ class MethodScanner implements ScannerInterface
$this->docComment = $tokenContent;
}
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_FINAL:
$this->isFinal = true;
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_ABSTRACT:
$this->isAbstract = true;
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_PUBLIC:
// use defaults
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_PROTECTED:
$this->setVisibility(T_PROTECTED);
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_PRIVATE:
$this->setVisibility(T_PRIVATE);
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_STATIC:
$this->isStatic = true;
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case T_NS_SEPARATOR:
if (! isset($infos[$infoIndex])) {
$MACRO_INFO_START();
}
goto SCANNER_CONTINUE_SIGNATURE;
// goto (no break needed);
case T_VARIABLE:
case T_STRING:
if ($tokenType === T_STRING && $parentCount === 0) {
$this->name = $tokenContent;
}
if ($parentCount === 1) {
if (!isset($infos[$infoIndex])) {
if (! isset($infos[$infoIndex])) {
$MACRO_INFO_START();
}
if ($tokenType === T_VARIABLE) {
@@ -539,21 +553,20 @@ class MethodScanner implements ScannerInterface
}
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case null:
switch ($tokenContent) {
case '&':
if (!isset($infos[$infoIndex])) {
if (! isset($infos[$infoIndex])) {
$MACRO_INFO_START();
}
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case '(':
$parentCount++;
goto SCANNER_CONTINUE_SIGNATURE;
//goto (no break needed);
// goto (no break needed);
case ')':
$parentCount--;
if ($parentCount > 0) {
@@ -566,7 +579,7 @@ class MethodScanner implements ScannerInterface
$context = 'body';
}
goto SCANNER_CONTINUE_BODY;
//goto (no break needed);
// goto (no break needed);
case ',':
if ($parentCount === 1) {
$MACRO_INFO_ADVANCE();
@@ -601,7 +614,5 @@ class MethodScanner implements ScannerInterface
SCANNER_END:
$this->isScanned = true;
return;
}
}

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
*/
@@ -11,6 +11,13 @@ namespace Zend\Code\Scanner;
use Zend\Code\NameInformation;
use function current;
use function is_string;
use function ltrim;
use function next;
use function reset;
use function trim;
class ParameterScanner
{
/**
@@ -21,42 +28,42 @@ class ParameterScanner
/**
* @var null|ClassScanner
*/
protected $declaringScannerClass = null;
protected $declaringScannerClass;
/**
* @var null|string
*/
protected $declaringClass = null;
protected $declaringClass;
/**
* @var null|MethodScanner
*/
protected $declaringScannerFunction = null;
protected $declaringScannerFunction;
/**
* @var null|string
*/
protected $declaringFunction = null;
protected $declaringFunction;
/**
* @var null|string
*/
protected $defaultValue = null;
protected $defaultValue;
/**
* @var null|string
*/
protected $class = null;
protected $class;
/**
* @var null|string
*/
protected $name = null;
protected $name;
/**
* @var null|int
*/
protected $position = null;
protected $position;
/**
* @var bool
@@ -81,12 +88,12 @@ class ParameterScanner
/**
* @var array|null
*/
protected $tokens = null;
protected $tokens;
/**
* @var null|NameInformation
*/
protected $nameInformation = null;
protected $nameInformation;
/**
* @param array $parameterTokens
@@ -195,7 +202,7 @@ class ParameterScanner
}
if ($this->name !== null) {
$this->defaultValue .= trim((is_string($token)) ? $token : $token[1]);
$this->defaultValue .= trim(is_string($token) ? $token : $token[1]);
}
SCANNER_CONTINUE:

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,13 +13,23 @@ use Zend\Code\Annotation;
use Zend\Code\Exception;
use Zend\Code\NameInformation;
use function is_array;
use function is_numeric;
use function is_string;
use function ltrim;
use function reset;
use function strpos;
use function substr;
use function trim;
use function var_export;
class PropertyScanner implements ScannerInterface
{
const T_BOOLEAN = "boolean";
const T_INTEGER = "int";
const T_STRING = "string";
const T_ARRAY = "array";
const T_UNKNOWN = "unknown";
const T_BOOLEAN = 'boolean';
const T_INTEGER = 'int';
const T_STRING = 'string';
const T_ARRAY = 'array';
const T_UNKNOWN = 'unknown';
/**
* @var bool
@@ -141,6 +151,7 @@ class PropertyScanner implements ScannerInterface
*/
public function getValueType()
{
$this->scan();
return $this->valueType;
}
@@ -200,7 +211,7 @@ class PropertyScanner implements ScannerInterface
/**
* @param Annotation\AnnotationManager $annotationManager
* @return AnnotationScanner
* @return AnnotationScanner|false
*/
public function getAnnotations(Annotation\AnnotationManager $annotationManager)
{
@@ -231,7 +242,7 @@ class PropertyScanner implements ScannerInterface
return;
}
if (!$this->tokens) {
if (! $this->tokens) {
throw new Exception\RuntimeException('No tokens were provided');
}
@@ -246,7 +257,7 @@ class PropertyScanner implements ScannerInterface
foreach ($tokens as $token) {
$tempValue = $token;
if (!is_string($token)) {
if (! is_string($token)) {
list($tokenType, $tokenContent, $tokenLine) = $token;
switch ($tokenType) {
@@ -284,7 +295,7 @@ class PropertyScanner implements ScannerInterface
}
//end value concatenation
if (!is_array($token) && trim($token) == ";") {
if (! is_array($token) && trim($token) == ';') {
$concatenateValue = false;
}
@@ -293,19 +304,19 @@ class PropertyScanner implements ScannerInterface
}
//start value concatenation
if (!is_array($token) && trim($token) == "=") {
if (! is_array($token) && trim($token) == '=') {
$concatenateValue = true;
}
}
$this->valueType = self::T_UNKNOWN;
if ($value == "false" || $value == "true") {
if ($value == 'false' || $value == 'true') {
$this->valueType = self::T_BOOLEAN;
} elseif (is_numeric($value)) {
$this->valueType = self::T_INTEGER;
} elseif (0 === strpos($value, 'array') || 0 === strpos($value, "[")) {
} elseif (0 === strpos($value, 'array') || 0 === strpos($value, '[')) {
$this->valueType = self::T_ARRAY;
} elseif (substr($value, 0, 1) === '"' || substr($value, 0, 1) === "'") {
} elseif (0 === strpos($value, '"') || 0 === strpos($value, "'")) {
$value = substr($value, 1, -1); // Remove quotes
$this->valueType = self::T_STRING;
}

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
*/

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;

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
*/
@@ -12,6 +12,16 @@ namespace Zend\Code\Scanner;
use stdClass;
use Zend\Code\Exception;
use function array_key_exists;
use function is_object;
use function ltrim;
use function property_exists;
use function sprintf;
use function strlen;
use function strpos;
use function substr;
use function substr_replace;
/**
* Shared utility methods used by scanners
*/
@@ -28,9 +38,9 @@ class Util
*/
public static function resolveImports(&$value, $key = null, stdClass $data = null)
{
if (!is_object($data)
|| !property_exists($data, 'uses')
|| !property_exists($data, 'namespace')
if (! is_object($data)
|| ! property_exists($data, 'uses')
|| ! property_exists($data, 'namespace')
) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a data object containing "uses" and "namespace" properties; on or both missing',
@@ -38,13 +48,13 @@ class Util
));
}
if ($data->namespace && !$data->uses && strlen($value) > 0 && $value{0} != '\\') {
if ($data->namespace && ! $data->uses && strlen($value) > 0 && $value[0] != '\\') {
$value = $data->namespace . '\\' . $value;
return;
}
if (!$data->uses || strlen($value) <= 0 || $value{0} == '\\') {
if (! $data->uses || strlen($value) <= 0 || $value[0] == '\\') {
$value = ltrim($value, '\\');
return;

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
*/