diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index 96066fd..b5639c3 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -166,7 +166,7 @@ class Lexer $nextFilePos = strpos($this->code, $tokenValue, $filePos); $this->handleInvalidCharacterRange( $filePos, $nextFilePos, $line, $errorHandler); - $filePos = $nextFilePos; + $filePos = (int)$nextFilePos; } $filePos += $tokenLen; diff --git a/lib/PhpParser/Node/Name.php b/lib/PhpParser/Node/Name.php index d3d33ea..93ade2f 100644 --- a/lib/PhpParser/Node/Name.php +++ b/lib/PhpParser/Node/Name.php @@ -15,8 +15,8 @@ class Name extends NodeAbstract /** * Constructs a name node. * - * @param string|array|self $name Name as string, part array or Name instance (copy ctor) - * @param array $attributes Additional attributes + * @param string|string[]|self $name Name as string, part array or Name instance (copy ctor) + * @param array $attributes Additional attributes */ public function __construct($name, array $attributes = array()) { parent::__construct($attributes); @@ -153,9 +153,9 @@ class Name extends NodeAbstract * Name::concat($namespace, $shortName) * where $namespace is a Name node or null will work as expected. * - * @param string|array|self|null $name1 The first name - * @param string|array|self|null $name2 The second name - * @param array $attributes Attributes to assign to concatenated name + * @param string|string[]|self|null $name1 The first name + * @param string|string[]|self|null $name2 The second name + * @param array $attributes Attributes to assign to concatenated name * * @return static|null Concatenated name */ @@ -177,9 +177,9 @@ class Name extends NodeAbstract * Prepares a (string, array or Name node) name for use in name changing methods by converting * it to an array. * - * @param string|array|self $name Name to prepare + * @param string|string[]|self $name Name to prepare * - * @return array Prepared name + * @return string[] Prepared name */ private static function prepareName($name) { if (\is_string($name)) { diff --git a/lib/PhpParser/Node/Scalar/Encapsed.php b/lib/PhpParser/Node/Scalar/Encapsed.php index 4f9b433..fbf3998 100644 --- a/lib/PhpParser/Node/Scalar/Encapsed.php +++ b/lib/PhpParser/Node/Scalar/Encapsed.php @@ -13,8 +13,8 @@ class Encapsed extends Scalar /** * Constructs an encapsed string node. * - * @param array $parts Encaps list - * @param array $attributes Additional attributes + * @param Expr[] $parts Encaps list + * @param array $attributes Additional attributes */ public function __construct(array $parts, array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/Node/Stmt/TryCatch.php b/lib/PhpParser/Node/Stmt/TryCatch.php index ae2fe57..eb44c46 100644 --- a/lib/PhpParser/Node/Stmt/TryCatch.php +++ b/lib/PhpParser/Node/Stmt/TryCatch.php @@ -19,7 +19,7 @@ class TryCatch extends Node\Stmt * @param Node\Stmt[] $stmts Statements * @param Catch_[] $catches Catches * @param null|Finally_ $finally Optionaly finally node - * @param array|null $attributes Additional attributes + * @param array $attributes Additional attributes */ public function __construct(array $stmts, array $catches, Finally_ $finally = null, array $attributes = array()) { parent::__construct($attributes); diff --git a/lib/PhpParser/NodeVisitor/FindingVisitor.php b/lib/PhpParser/NodeVisitor/FindingVisitor.php index 09898dc..dc152fe 100644 --- a/lib/PhpParser/NodeVisitor/FindingVisitor.php +++ b/lib/PhpParser/NodeVisitor/FindingVisitor.php @@ -32,6 +32,8 @@ class FindingVisitor extends NodeVisitorAbstract { public function beforeTraverse(array $nodes) { $this->foundNodes = []; + + return null; } public function enterNode(Node $node) { @@ -39,5 +41,7 @@ class FindingVisitor extends NodeVisitorAbstract { if ($filterCallback($node)) { $this->foundNodes[] = $node; } + + return null; } } \ No newline at end of file diff --git a/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php b/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php index 0e4b978..c3b97af 100644 --- a/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php +++ b/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php @@ -33,6 +33,8 @@ class FirstFindingVisitor extends NodeVisitorAbstract { public function beforeTraverse(array $nodes) { $this->foundNode = null; + + return null; } public function enterNode(Node $node) { diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index 66391d7..e4abb7b 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -17,7 +17,7 @@ class NameResolver extends NodeVisitorAbstract protected $namespace; /** @var array Map of format [aliasType => [aliasName => originalName]] */ - protected $aliases; + protected $aliases = []; /** @var ErrorHandler Error handler */ protected $errorHandler; diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index 8364a55..deb2263 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -581,6 +581,20 @@ abstract class ParserAbstract implements Parser return $style; } + /** + * Fix up parsing of static property calls in PHP 5. + * + * In PHP 5 A::$b[c][d] and A::$b[c][d]() have very different interpretation. The former is + * interpreted as (A::$b)[c][d], while the latter is the same as A::{$b[c][d]}(). We parse the + * latter as the former initially and this method fixes the AST into the correct form when we + * encounter the "()". + * + * @param Node\Expr\StaticPropertyFetch|Node\Expr\ArrayDimFetch $prop + * @param Node\Arg[] $args + * @param array $attributes + * + * @return Expr\StaticCall + */ protected function fixupPhp5StaticPropCall($prop, array $args, array $attributes) { if ($prop instanceof Node\Expr\StaticPropertyFetch) { // Preserve attributes if possible @@ -631,9 +645,6 @@ abstract class ParserAbstract implements Parser } } - /** - * @return string - */ protected function handleBuiltinTypes(Name $name) { $scalarTypes = [ 'bool' => true,