From b3ad14b93843145117253a61d5f26ebf03be8733 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 17 Sep 2022 20:33:04 +0200 Subject: [PATCH] Fix some types --- lib/PhpParser/Builder/FunctionLike.php | 2 +- lib/PhpParser/Builder/TraitUseAdaptation.php | 2 +- lib/PhpParser/BuilderFactory.php | 4 ++-- lib/PhpParser/Comment.php | 2 +- lib/PhpParser/Internal/PrintableNewAnonClassNode.php | 4 ++-- lib/PhpParser/JsonDecoder.php | 1 + lib/PhpParser/Node/Stmt/ClassMethod.php | 2 +- lib/PhpParser/NodeVisitor/NameResolver.php | 2 +- 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/PhpParser/Builder/FunctionLike.php b/lib/PhpParser/Builder/FunctionLike.php index 5af887e46a..b62ff223a8 100644 --- a/lib/PhpParser/Builder/FunctionLike.php +++ b/lib/PhpParser/Builder/FunctionLike.php @@ -11,7 +11,7 @@ abstract class FunctionLike extends Declaration { /** @var Node\Param[] */ protected $params = []; - /** @var string|Node\Name|Node\NullableType|null */ + /** @var Node\Identifier|Node\Name|Node\ComplexType|null */ protected $returnType = null; /** diff --git a/lib/PhpParser/Builder/TraitUseAdaptation.php b/lib/PhpParser/Builder/TraitUseAdaptation.php index eec491a2b8..6fceb1f0e4 100644 --- a/lib/PhpParser/Builder/TraitUseAdaptation.php +++ b/lib/PhpParser/Builder/TraitUseAdaptation.php @@ -55,7 +55,7 @@ public function as($alias) { throw new \LogicException('Cannot set alias for not alias adaptation buider'); } - $this->alias = $alias; + $this->alias = BuilderHelpers::normalizeIdentifier($alias); return $this; } diff --git a/lib/PhpParser/BuilderFactory.php b/lib/PhpParser/BuilderFactory.php index 4e77f857a9..fa20a7c5fa 100644 --- a/lib/PhpParser/BuilderFactory.php +++ b/lib/PhpParser/BuilderFactory.php @@ -86,7 +86,7 @@ public function enum(string $name): Builder\Enum_ { * * @param Node\Name|string ...$traits Trait names * - * @return Builder\TraitUse The create trait use builder + * @return Builder\TraitUse The created trait use builder */ public function useTrait(...$traits): Builder\TraitUse { return new Builder\TraitUse(...$traits); @@ -98,7 +98,7 @@ public function useTrait(...$traits): Builder\TraitUse { * @param Node\Name|string|null $trait Trait name * @param Node\Identifier|string $method Method name * - * @return Builder\TraitUseAdaptation The create trait use adaptation builder + * @return Builder\TraitUseAdaptation The created trait use adaptation builder */ public function traitUseAdaptation($trait, $method = null): Builder\TraitUseAdaptation { if ($method === null) { diff --git a/lib/PhpParser/Comment.php b/lib/PhpParser/Comment.php index b533c59dd8..ff949d9b35 100644 --- a/lib/PhpParser/Comment.php +++ b/lib/PhpParser/Comment.php @@ -215,7 +215,7 @@ public function getReformattedText() { */ private function getShortestWhitespacePrefixLen(string $str): int { $lines = explode("\n", $str); - $shortestPrefixLen = \INF; + $shortestPrefixLen = \PHP_INT_MAX; foreach ($lines as $line) { preg_match('(^\s*)', $line, $matches); $prefixLen = strlen($matches[0]); diff --git a/lib/PhpParser/Internal/PrintableNewAnonClassNode.php b/lib/PhpParser/Internal/PrintableNewAnonClassNode.php index 4cb758c041..f60e04073a 100644 --- a/lib/PhpParser/Internal/PrintableNewAnonClassNode.php +++ b/lib/PhpParser/Internal/PrintableNewAnonClassNode.php @@ -18,7 +18,7 @@ class PrintableNewAnonClassNode extends Expr { /** @var Node\AttributeGroup[] PHP attribute groups */ public $attrGroups; - /** @var Node\Arg[] Arguments */ + /** @var (Node\Arg|Node\VariadicPlaceholder)[] Arguments */ public $args; /** @var null|Node\Name Name of extended class */ public $extends; @@ -29,7 +29,7 @@ class PrintableNewAnonClassNode extends Expr { /** * @param Node\AttributeGroup[] $attrGroups PHP attribute groups - * @param Node\Arg[] $args Arguments + * @param (Node\Arg|Node\VariadicPlaceholder)[] $args Arguments * @param Node\Name|null $extends Name of extended class * @param Node\Name[] $implements Names of implemented interfaces * @param Node\Stmt[] $stmts Statements diff --git a/lib/PhpParser/JsonDecoder.php b/lib/PhpParser/JsonDecoder.php index 7b0ac0459d..bd9d59c827 100644 --- a/lib/PhpParser/JsonDecoder.php +++ b/lib/PhpParser/JsonDecoder.php @@ -91,6 +91,7 @@ private function reflectionClassFromNodeType(string $nodeType): \ReflectionClass return $this->reflectionClassCache[$nodeType]; } + /** @return class-string */ private function classNameFromNodeType(string $nodeType): string { $className = 'PhpParser\\Node\\' . strtr($nodeType, '_', '\\'); if (class_exists($className)) { diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 927e6f3408..3cadfd86d9 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -52,7 +52,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike { * byRef?: bool, * params?: Node\Param[], * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, - * stmts?: Node\Stmt[], + * stmts?: Node\Stmt[]|null, * attrGroups?: Node\AttributeGroup[], * } $subNodes Array of the following optional subnodes: * 'flags => 0 : Flags diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index a6c1fd663d..996a9d6897 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -171,7 +171,7 @@ private function addAlias(Node\UseItem $use, int $type, ?Name $prefix = null): v ); } - /** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure $node */ + /** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure|Expr\ArrowFunction $node */ private function resolveSignature($node): void { foreach ($node->params as $param) { $param->type = $this->resolveType($param->type);