mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-06 03:10:50 +00:00
Updated Rector to commit 3ef3e35c45970bce4000f45f9c1cb651f078c5a0
3ef3e35c45
[Php71] Skip re-assign as string on AssignArrayToStringRector part 2 (#5661)
This commit is contained in:
parent
dcd788c4dd
commit
cd427d527e
|
@ -3,6 +3,7 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\Php71\Rector\Assign;
|
namespace Rector\Php71\Rector\Assign;
|
||||||
|
|
||||||
|
use PHPStan\Type\UnionType;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr;
|
use PhpParser\Node\Expr;
|
||||||
use PhpParser\Node\Expr\Array_;
|
use PhpParser\Node\Expr\Array_;
|
||||||
|
@ -186,7 +187,11 @@ CODE_SAMPLE
|
||||||
if (!$this->isEmptyString($assign->expr)) {
|
if (!$this->isEmptyString($assign->expr)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ($this->nodeTypeResolver->getNativeType($assign->var)->isArray()->yes()) {
|
$type = $this->nodeTypeResolver->getNativeType($assign->var);
|
||||||
|
if ($type->isArray()->yes()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($type instanceof UnionType) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$variableAssignArrayDimFetches = $this->findSameNamedVariableAssigns($assign->var, $node);
|
$variableAssignArrayDimFetches = $this->findSameNamedVariableAssigns($assign->var, $node);
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '2d1f468bc6e41bc84dc273c8ac94033b60761a76';
|
public const PACKAGE_VERSION = '3ef3e35c45970bce4000f45f9c1cb651f078c5a0';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2024-02-23 20:04:16';
|
public const RELEASE_DATE = '2024-02-24 02:26:27';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
|
@ -858,17 +858,17 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan\/phpdoc-parser",
|
"name": "phpstan\/phpdoc-parser",
|
||||||
"version": "1.25.0",
|
"version": "1.26.0",
|
||||||
"version_normalized": "1.25.0.0",
|
"version_normalized": "1.26.0.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
|
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
|
||||||
"reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240"
|
"reference": "231e3186624c03d7e7c890ec662b81e6b0405227"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/bd84b629c8de41aa2ae82c067c955e06f1b00240",
|
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/231e3186624c03d7e7c890ec662b81e6b0405227",
|
||||||
"reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240",
|
"reference": "231e3186624c03d7e7c890ec662b81e6b0405227",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -885,7 +885,7 @@
|
||||||
"phpunit\/phpunit": "^9.5",
|
"phpunit\/phpunit": "^9.5",
|
||||||
"symfony\/process": "^5.2"
|
"symfony\/process": "^5.2"
|
||||||
},
|
},
|
||||||
"time": "2024-01-04T17:06:16+00:00",
|
"time": "2024-02-23T16:05:55+00:00",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"installation-source": "dist",
|
"installation-source": "dist",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -902,7 +902,7 @@
|
||||||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
|
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
|
||||||
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.25.0"
|
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.26.0"
|
||||||
},
|
},
|
||||||
"install-path": "..\/phpstan\/phpdoc-parser"
|
"install-path": "..\/phpstan\/phpdoc-parser"
|
||||||
},
|
},
|
||||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
|
@ -4,24 +4,29 @@ declare (strict_types=1);
|
||||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||||
|
|
||||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
|
||||||
use function implode;
|
use function implode;
|
||||||
class CallableTypeNode implements \PHPStan\PhpDocParser\Ast\Type\TypeNode
|
class CallableTypeNode implements \PHPStan\PhpDocParser\Ast\Type\TypeNode
|
||||||
{
|
{
|
||||||
use NodeAttributes;
|
use NodeAttributes;
|
||||||
/** @var IdentifierTypeNode */
|
/** @var IdentifierTypeNode */
|
||||||
public $identifier;
|
public $identifier;
|
||||||
|
/** @var TemplateTagValueNode[] */
|
||||||
|
public $templateTypes;
|
||||||
/** @var CallableTypeParameterNode[] */
|
/** @var CallableTypeParameterNode[] */
|
||||||
public $parameters;
|
public $parameters;
|
||||||
/** @var TypeNode */
|
/** @var TypeNode */
|
||||||
public $returnType;
|
public $returnType;
|
||||||
/**
|
/**
|
||||||
* @param CallableTypeParameterNode[] $parameters
|
* @param CallableTypeParameterNode[] $parameters
|
||||||
|
* @param TemplateTagValueNode[] $templateTypes
|
||||||
*/
|
*/
|
||||||
public function __construct(\PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode $identifier, array $parameters, \PHPStan\PhpDocParser\Ast\Type\TypeNode $returnType)
|
public function __construct(\PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode $identifier, array $parameters, \PHPStan\PhpDocParser\Ast\Type\TypeNode $returnType, array $templateTypes = [])
|
||||||
{
|
{
|
||||||
$this->identifier = $identifier;
|
$this->identifier = $identifier;
|
||||||
$this->parameters = $parameters;
|
$this->parameters = $parameters;
|
||||||
$this->returnType = $returnType;
|
$this->returnType = $returnType;
|
||||||
|
$this->templateTypes = $templateTypes;
|
||||||
}
|
}
|
||||||
public function __toString() : string
|
public function __toString() : string
|
||||||
{
|
{
|
||||||
|
@ -29,7 +34,8 @@ class CallableTypeNode implements \PHPStan\PhpDocParser\Ast\Type\TypeNode
|
||||||
if ($returnType instanceof self) {
|
if ($returnType instanceof self) {
|
||||||
$returnType = "({$returnType})";
|
$returnType = "({$returnType})";
|
||||||
}
|
}
|
||||||
|
$template = $this->templateTypes !== [] ? '<' . implode(', ', $this->templateTypes) . '>' : '';
|
||||||
$parameters = implode(', ', $this->parameters);
|
$parameters = implode(', ', $this->parameters);
|
||||||
return "{$this->identifier}({$parameters}): {$returnType}";
|
return "{$this->identifier}{$template}({$parameters}): {$returnType}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,7 +337,9 @@ class PhpDocParser
|
||||||
case '@template-contravariant':
|
case '@template-contravariant':
|
||||||
case '@phpstan-template-contravariant':
|
case '@phpstan-template-contravariant':
|
||||||
case '@psalm-template-contravariant':
|
case '@psalm-template-contravariant':
|
||||||
$tagValue = $this->parseTemplateTagValue($tokens, \true);
|
$tagValue = $this->typeParser->parseTemplateTagValue($tokens, function ($tokens) {
|
||||||
|
return $this->parseOptionalDescription($tokens);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case '@extends':
|
case '@extends':
|
||||||
case '@phpstan-extends':
|
case '@phpstan-extends':
|
||||||
|
@ -638,16 +640,20 @@ class PhpDocParser
|
||||||
}
|
}
|
||||||
private function parseMethodTagValue(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\MethodTagValueNode
|
private function parseMethodTagValue(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\MethodTagValueNode
|
||||||
{
|
{
|
||||||
$isStatic = $tokens->tryConsumeTokenValue('static');
|
$staticKeywordOrReturnTypeOrMethodName = $this->typeParser->parse($tokens);
|
||||||
$startLine = $tokens->currentTokenLine();
|
if ($staticKeywordOrReturnTypeOrMethodName instanceof Ast\Type\IdentifierTypeNode && $staticKeywordOrReturnTypeOrMethodName->name === 'static') {
|
||||||
$startIndex = $tokens->currentTokenIndex();
|
$isStatic = \true;
|
||||||
$returnTypeOrMethodName = $this->typeParser->parse($tokens);
|
$returnTypeOrMethodName = $this->typeParser->parse($tokens);
|
||||||
|
} else {
|
||||||
|
$isStatic = \false;
|
||||||
|
$returnTypeOrMethodName = $staticKeywordOrReturnTypeOrMethodName;
|
||||||
|
}
|
||||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_IDENTIFIER)) {
|
if ($tokens->isCurrentTokenType(Lexer::TOKEN_IDENTIFIER)) {
|
||||||
$returnType = $returnTypeOrMethodName;
|
$returnType = $returnTypeOrMethodName;
|
||||||
$methodName = $tokens->currentTokenValue();
|
$methodName = $tokens->currentTokenValue();
|
||||||
$tokens->next();
|
$tokens->next();
|
||||||
} elseif ($returnTypeOrMethodName instanceof Ast\Type\IdentifierTypeNode) {
|
} elseif ($returnTypeOrMethodName instanceof Ast\Type\IdentifierTypeNode) {
|
||||||
$returnType = $isStatic ? $this->typeParser->enrichWithAttributes($tokens, new Ast\Type\IdentifierTypeNode('static'), $startLine, $startIndex) : null;
|
$returnType = $isStatic ? $staticKeywordOrReturnTypeOrMethodName : null;
|
||||||
$methodName = $returnTypeOrMethodName->name;
|
$methodName = $returnTypeOrMethodName->name;
|
||||||
$isStatic = \false;
|
$isStatic = \false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -660,7 +666,7 @@ class PhpDocParser
|
||||||
do {
|
do {
|
||||||
$startLine = $tokens->currentTokenLine();
|
$startLine = $tokens->currentTokenLine();
|
||||||
$startIndex = $tokens->currentTokenIndex();
|
$startIndex = $tokens->currentTokenIndex();
|
||||||
$templateTypes[] = $this->enrichWithAttributes($tokens, $this->parseTemplateTagValue($tokens, \false), $startLine, $startIndex);
|
$templateTypes[] = $this->enrichWithAttributes($tokens, $this->typeParser->parseTemplateTagValue($tokens), $startLine, $startIndex);
|
||||||
} while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA));
|
} while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA));
|
||||||
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
|
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
|
||||||
}
|
}
|
||||||
|
@ -700,27 +706,6 @@ class PhpDocParser
|
||||||
}
|
}
|
||||||
return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\MethodTagValueParameterNode($parameterType, $isReference, $isVariadic, $parameterName, $defaultValue), $startLine, $startIndex);
|
return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\MethodTagValueParameterNode($parameterType, $isReference, $isVariadic, $parameterName, $defaultValue), $startLine, $startIndex);
|
||||||
}
|
}
|
||||||
private function parseTemplateTagValue(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens, bool $parseDescription) : Ast\PhpDoc\TemplateTagValueNode
|
|
||||||
{
|
|
||||||
$name = $tokens->currentTokenValue();
|
|
||||||
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
|
|
||||||
if ($tokens->tryConsumeTokenValue('of') || $tokens->tryConsumeTokenValue('as')) {
|
|
||||||
$bound = $this->typeParser->parse($tokens);
|
|
||||||
} else {
|
|
||||||
$bound = null;
|
|
||||||
}
|
|
||||||
if ($tokens->tryConsumeTokenValue('=')) {
|
|
||||||
$default = $this->typeParser->parse($tokens);
|
|
||||||
} else {
|
|
||||||
$default = null;
|
|
||||||
}
|
|
||||||
if ($parseDescription) {
|
|
||||||
$description = $this->parseOptionalDescription($tokens);
|
|
||||||
} else {
|
|
||||||
$description = '';
|
|
||||||
}
|
|
||||||
return new Ast\PhpDoc\TemplateTagValueNode($name, $bound, $description, $default);
|
|
||||||
}
|
|
||||||
private function parseExtendsTagValue(string $tagName, \PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\PhpDocTagValueNode
|
private function parseExtendsTagValue(string $tagName, \PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\PhpDocTagValueNode
|
||||||
{
|
{
|
||||||
$startLine = $tokens->currentTokenLine();
|
$startLine = $tokens->currentTokenLine();
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace PHPStan\PhpDocParser\Parser;
|
||||||
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use PHPStan\PhpDocParser\Ast;
|
use PHPStan\PhpDocParser\Ast;
|
||||||
|
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
|
||||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
use function str_replace;
|
use function str_replace;
|
||||||
|
@ -128,12 +129,16 @@ class TypeParser
|
||||||
if ($isHtml) {
|
if ($isHtml) {
|
||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
$type = $this->parseGeneric($tokens, $type);
|
$origType = $type;
|
||||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
$type = $this->tryParseCallable($tokens, $type, \true);
|
||||||
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
if ($type === $origType) {
|
||||||
|
$type = $this->parseGeneric($tokens, $type);
|
||||||
|
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
||||||
|
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) {
|
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) {
|
||||||
$type = $this->tryParseCallable($tokens, $type);
|
$type = $this->tryParseCallable($tokens, $type, \false);
|
||||||
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
||||||
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
||||||
} elseif (in_array($type->name, ['array', 'list', 'object'], \true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
} elseif (in_array($type->name, ['array', 'list', 'object'], \true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||||
|
@ -329,9 +334,35 @@ class TypeParser
|
||||||
$type = $this->parse($tokens);
|
$type = $this->parse($tokens);
|
||||||
return [$type, $variance];
|
return [$type, $variance];
|
||||||
}
|
}
|
||||||
/** @phpstan-impure */
|
/**
|
||||||
private function parseCallable(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens, Ast\Type\IdentifierTypeNode $identifier) : Ast\Type\TypeNode
|
* @throws ParserException
|
||||||
|
* @param ?callable(TokenIterator): string $parseDescription
|
||||||
|
*/
|
||||||
|
public function parseTemplateTagValue(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens, ?callable $parseDescription = null) : TemplateTagValueNode
|
||||||
{
|
{
|
||||||
|
$name = $tokens->currentTokenValue();
|
||||||
|
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
|
||||||
|
if ($tokens->tryConsumeTokenValue('of') || $tokens->tryConsumeTokenValue('as')) {
|
||||||
|
$bound = $this->parse($tokens);
|
||||||
|
} else {
|
||||||
|
$bound = null;
|
||||||
|
}
|
||||||
|
if ($tokens->tryConsumeTokenValue('=')) {
|
||||||
|
$default = $this->parse($tokens);
|
||||||
|
} else {
|
||||||
|
$default = null;
|
||||||
|
}
|
||||||
|
if ($parseDescription !== null) {
|
||||||
|
$description = $parseDescription($tokens);
|
||||||
|
} else {
|
||||||
|
$description = '';
|
||||||
|
}
|
||||||
|
return new Ast\PhpDoc\TemplateTagValueNode($name, $bound, $description, $default);
|
||||||
|
}
|
||||||
|
/** @phpstan-impure */
|
||||||
|
private function parseCallable(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens, Ast\Type\IdentifierTypeNode $identifier, bool $hasTemplate) : Ast\Type\TypeNode
|
||||||
|
{
|
||||||
|
$templates = $hasTemplate ? $this->parseCallableTemplates($tokens) : [];
|
||||||
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_PARENTHESES);
|
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_PARENTHESES);
|
||||||
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||||
$parameters = [];
|
$parameters = [];
|
||||||
|
@ -352,7 +383,36 @@ class TypeParser
|
||||||
$startLine = $tokens->currentTokenLine();
|
$startLine = $tokens->currentTokenLine();
|
||||||
$startIndex = $tokens->currentTokenIndex();
|
$startIndex = $tokens->currentTokenIndex();
|
||||||
$returnType = $this->enrichWithAttributes($tokens, $this->parseCallableReturnType($tokens), $startLine, $startIndex);
|
$returnType = $this->enrichWithAttributes($tokens, $this->parseCallableReturnType($tokens), $startLine, $startIndex);
|
||||||
return new Ast\Type\CallableTypeNode($identifier, $parameters, $returnType);
|
return new Ast\Type\CallableTypeNode($identifier, $parameters, $returnType, $templates);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return Ast\PhpDoc\TemplateTagValueNode[]
|
||||||
|
*
|
||||||
|
* @phpstan-impure
|
||||||
|
*/
|
||||||
|
private function parseCallableTemplates(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : array
|
||||||
|
{
|
||||||
|
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
|
||||||
|
$templates = [];
|
||||||
|
$isFirst = \true;
|
||||||
|
while ($isFirst || $tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
|
||||||
|
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||||
|
// trailing comma case
|
||||||
|
if (!$isFirst && $tokens->isCurrentTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$isFirst = \false;
|
||||||
|
$templates[] = $this->parseCallableTemplateArgument($tokens);
|
||||||
|
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
||||||
|
}
|
||||||
|
$tokens->consumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET);
|
||||||
|
return $templates;
|
||||||
|
}
|
||||||
|
private function parseCallableTemplateArgument(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\TemplateTagValueNode
|
||||||
|
{
|
||||||
|
$startLine = $tokens->currentTokenLine();
|
||||||
|
$startIndex = $tokens->currentTokenIndex();
|
||||||
|
return $this->enrichWithAttributes($tokens, $this->parseTemplateTagValue($tokens), $startLine, $startIndex);
|
||||||
}
|
}
|
||||||
/** @phpstan-impure */
|
/** @phpstan-impure */
|
||||||
private function parseCallableParameter(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\Type\CallableTypeParameterNode
|
private function parseCallableParameter(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\Type\CallableTypeParameterNode
|
||||||
|
@ -447,11 +507,11 @@ class TypeParser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** @phpstan-impure */
|
/** @phpstan-impure */
|
||||||
private function tryParseCallable(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens, Ast\Type\IdentifierTypeNode $identifier) : Ast\Type\TypeNode
|
private function tryParseCallable(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens, Ast\Type\IdentifierTypeNode $identifier, bool $hasTemplate) : Ast\Type\TypeNode
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$tokens->pushSavePoint();
|
$tokens->pushSavePoint();
|
||||||
$type = $this->parseCallable($tokens, $identifier);
|
$type = $this->parseCallable($tokens, $identifier, $hasTemplate);
|
||||||
$tokens->dropSavePoint();
|
$tokens->dropSavePoint();
|
||||||
} catch (\PHPStan\PhpDocParser\Parser\ParserException $e) {
|
} catch (\PHPStan\PhpDocParser\Parser\ParserException $e) {
|
||||||
$tokens->rollback();
|
$tokens->rollback();
|
||||||
|
|
|
@ -90,7 +90,7 @@ final class Printer
|
||||||
*
|
*
|
||||||
* @var array<string, string>
|
* @var array<string, string>
|
||||||
*/
|
*/
|
||||||
private $listInsertionMap = [PhpDocNode::class . '->children' => "\n * ", UnionTypeNode::class . '->types' => '|', IntersectionTypeNode::class . '->types' => '&', ArrayShapeNode::class . '->items' => ', ', ObjectShapeNode::class . '->items' => ', ', CallableTypeNode::class . '->parameters' => ', ', GenericTypeNode::class . '->genericTypes' => ', ', ConstExprArrayNode::class . '->items' => ', ', MethodTagValueNode::class . '->parameters' => ', ', DoctrineArray::class . '->items' => ', ', DoctrineAnnotation::class . '->arguments' => ', '];
|
private $listInsertionMap = [PhpDocNode::class . '->children' => "\n * ", UnionTypeNode::class . '->types' => '|', IntersectionTypeNode::class . '->types' => '&', ArrayShapeNode::class . '->items' => ', ', ObjectShapeNode::class . '->items' => ', ', CallableTypeNode::class . '->parameters' => ', ', CallableTypeNode::class . '->templateTypes' => ', ', GenericTypeNode::class . '->genericTypes' => ', ', ConstExprArrayNode::class . '->items' => ', ', MethodTagValueNode::class . '->parameters' => ', ', DoctrineArray::class . '->items' => ', ', DoctrineAnnotation::class . '->arguments' => ', '];
|
||||||
/**
|
/**
|
||||||
* [$find, $extraLeft, $extraRight]
|
* [$find, $extraLeft, $extraRight]
|
||||||
*
|
*
|
||||||
|
@ -294,10 +294,13 @@ final class Printer
|
||||||
} else {
|
} else {
|
||||||
$returnType = $this->printType($node->returnType);
|
$returnType = $this->printType($node->returnType);
|
||||||
}
|
}
|
||||||
|
$template = $node->templateTypes !== [] ? '<' . implode(', ', array_map(function (TemplateTagValueNode $templateNode) : string {
|
||||||
|
return $this->print($templateNode);
|
||||||
|
}, $node->templateTypes)) . '>' : '';
|
||||||
$parameters = implode(', ', array_map(function (CallableTypeParameterNode $parameterNode) : string {
|
$parameters = implode(', ', array_map(function (CallableTypeParameterNode $parameterNode) : string {
|
||||||
return $this->print($parameterNode);
|
return $this->print($parameterNode);
|
||||||
}, $node->parameters));
|
}, $node->parameters));
|
||||||
return "{$node->identifier}({$parameters}): {$returnType}";
|
return "{$node->identifier}{$template}({$parameters}): {$returnType}";
|
||||||
}
|
}
|
||||||
if ($node instanceof ConditionalTypeForParameterNode) {
|
if ($node instanceof ConditionalTypeForParameterNode) {
|
||||||
return sprintf('(%s %s %s ? %s : %s)', $node->parameterName, $node->negated ? 'is not' : 'is', $this->printType($node->targetType), $this->printType($node->if), $this->printType($node->else));
|
return sprintf('(%s %s %s ? %s : %s)', $node->parameterName, $node->negated ? 'is not' : 'is', $this->printType($node->targetType), $this->printType($node->if), $this->printType($node->else));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user