mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-19 06:52:51 +02:00
Updated Rector to commit 6658a0e3950589eface36a82af5be21bef70bf11
6658a0e395
[TypeDeclaration] Skip coalesce on StrictArrayParamDimFetchRector (#4589)
This commit is contained in:
parent
dd741c0c67
commit
a89d98c36c
@ -5,6 +5,8 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\AssignOp\Coalesce as AssignOpCoalesce;
|
||||
use PhpParser\Node\Expr\BinaryOp\Coalesce;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
@ -91,11 +93,10 @@ CODE_SAMPLE
|
||||
$paramName = $this->getName($param);
|
||||
$isParamAccessedArrayDimFetch = \false;
|
||||
$this->traverseNodesWithCallable($functionLike, function (Node $node) use($paramName, &$isParamAccessedArrayDimFetch) : ?int {
|
||||
if ($node instanceof FuncCall && $this->isNames($node, ['is_array', 'is_string', 'is_int', 'is_bool', 'is_float'])) {
|
||||
$firstArg = $node->getArgs()[0];
|
||||
if ($this->isName($firstArg->value, $paramName)) {
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
}
|
||||
if ($this->shouldStop($node, $paramName)) {
|
||||
// force set to false to avoid too early replaced
|
||||
$isParamAccessedArrayDimFetch = \false;
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
}
|
||||
if (!$node instanceof ArrayDimFetch) {
|
||||
return null;
|
||||
@ -111,4 +112,15 @@ CODE_SAMPLE
|
||||
});
|
||||
return $isParamAccessedArrayDimFetch;
|
||||
}
|
||||
private function shouldStop(Node $node, string $paramName) : bool
|
||||
{
|
||||
if ($node instanceof FuncCall && !$node->isFirstClassCallable() && $this->isNames($node, ['is_array', 'is_string', 'is_int', 'is_bool', 'is_float'])) {
|
||||
$firstArg = $node->getArgs()[0];
|
||||
return $firstArg->value instanceof Variable && $this->isName($firstArg->value, $paramName);
|
||||
}
|
||||
if ($node instanceof Coalesce && $node->left instanceof Variable && $this->isName($node->left, $paramName)) {
|
||||
return \true;
|
||||
}
|
||||
return $node instanceof AssignOpCoalesce && $node->var instanceof Variable && $this->isName($node->var, $paramName);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'e9e6a42eaea1006ac822ba72902806a7d6f7e508';
|
||||
public const PACKAGE_VERSION = '6658a0e3950589eface36a82af5be21bef70bf11';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-24 15:16:03';
|
||||
public const RELEASE_DATE = '2023-07-24 19:36:19';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit4b3f35d5a87c1f8cca91002e4906d48e::getLoader();
|
||||
return ComposerAutoloaderInit60c92db3ff25efa41d55c57f37538394::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit4b3f35d5a87c1f8cca91002e4906d48e
|
||||
class ComposerAutoloaderInit60c92db3ff25efa41d55c57f37538394
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit4b3f35d5a87c1f8cca91002e4906d48e
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit4b3f35d5a87c1f8cca91002e4906d48e', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit60c92db3ff25efa41d55c57f37538394', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit4b3f35d5a87c1f8cca91002e4906d48e', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit60c92db3ff25efa41d55c57f37538394', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit60c92db3ff25efa41d55c57f37538394::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit60c92db3ff25efa41d55c57f37538394::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e
|
||||
class ComposerStaticInit60c92db3ff25efa41d55c57f37538394
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3022,9 +3022,9 @@ class ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit4b3f35d5a87c1f8cca91002e4906d48e::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit60c92db3ff25efa41d55c57f37538394::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit60c92db3ff25efa41d55c57f37538394::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit60c92db3ff25efa41d55c57f37538394::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
@ -926,17 +926,17 @@
|
||||
},
|
||||
{
|
||||
"name": "phpstan\/phpdoc-parser",
|
||||
"version": "1.22.1",
|
||||
"version_normalized": "1.22.1.0",
|
||||
"version": "1.23.0",
|
||||
"version_normalized": "1.23.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
|
||||
"reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0"
|
||||
"reference": "a2b24135c35852b348894320d47b3902a94bc494"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/65c39594fbd8c67abfc68bb323f86447bab79cc0",
|
||||
"reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/a2b24135c35852b348894320d47b3902a94bc494",
|
||||
"reference": "a2b24135c35852b348894320d47b3902a94bc494",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -953,7 +953,7 @@
|
||||
"phpunit\/phpunit": "^9.5",
|
||||
"symfony\/process": "^5.2"
|
||||
},
|
||||
"time": "2023-06-29T20:46:06+00:00",
|
||||
"time": "2023-07-23T22:17:56+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
@ -970,7 +970,7 @@
|
||||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
|
||||
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.22.1"
|
||||
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.23.0"
|
||||
},
|
||||
"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
@ -15,6 +15,7 @@ use PHPStan\ShouldNotHappenException;
|
||||
use function array_key_exists;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function rtrim;
|
||||
use function str_replace;
|
||||
use function trim;
|
||||
/**
|
||||
@ -37,10 +38,12 @@ class PhpDocParser
|
||||
private $useLinesAttributes;
|
||||
/** @var bool */
|
||||
private $useIndexAttributes;
|
||||
/** @var bool */
|
||||
private $textBetweenTagsBelongsToDescription;
|
||||
/**
|
||||
* @param array{lines?: bool, indexes?: bool} $usedAttributes
|
||||
*/
|
||||
public function __construct(\PHPStan\PhpDocParser\Parser\TypeParser $typeParser, \PHPStan\PhpDocParser\Parser\ConstExprParser $constantExprParser, bool $requireWhitespaceBeforeDescription = \false, bool $preserveTypeAliasesWithInvalidTypes = \false, array $usedAttributes = [], bool $parseDoctrineAnnotations = \false)
|
||||
public function __construct(\PHPStan\PhpDocParser\Parser\TypeParser $typeParser, \PHPStan\PhpDocParser\Parser\ConstExprParser $constantExprParser, bool $requireWhitespaceBeforeDescription = \false, bool $preserveTypeAliasesWithInvalidTypes = \false, array $usedAttributes = [], bool $parseDoctrineAnnotations = \false, bool $textBetweenTagsBelongsToDescription = \false)
|
||||
{
|
||||
$this->typeParser = $typeParser;
|
||||
$this->constantExprParser = $constantExprParser;
|
||||
@ -49,6 +52,7 @@ class PhpDocParser
|
||||
$this->parseDoctrineAnnotations = $parseDoctrineAnnotations;
|
||||
$this->useLinesAttributes = $usedAttributes['lines'] ?? \false;
|
||||
$this->useIndexAttributes = $usedAttributes['indexes'] ?? \false;
|
||||
$this->textBetweenTagsBelongsToDescription = $textBetweenTagsBelongsToDescription;
|
||||
}
|
||||
public function parse(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\PhpDocNode
|
||||
{
|
||||
@ -149,27 +153,59 @@ class PhpDocParser
|
||||
private function parseText(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\PhpDocTextNode
|
||||
{
|
||||
$text = '';
|
||||
while (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
|
||||
$text .= $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END);
|
||||
$endTokens = [Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END];
|
||||
if ($this->textBetweenTagsBelongsToDescription) {
|
||||
$endTokens = [Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END];
|
||||
}
|
||||
$savepoint = \false;
|
||||
// if the next token is EOL, everything below is skipped and empty string is returned
|
||||
while ($this->textBetweenTagsBelongsToDescription || !$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
|
||||
$tmpText = $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_EOL, ...$endTokens);
|
||||
$text .= $tmpText;
|
||||
// stop if we're not at EOL - meaning it's the end of PHPDoc
|
||||
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
|
||||
break;
|
||||
}
|
||||
if ($this->textBetweenTagsBelongsToDescription) {
|
||||
if (!$savepoint) {
|
||||
$tokens->pushSavePoint();
|
||||
$savepoint = \true;
|
||||
} elseif ($tmpText !== '') {
|
||||
$tokens->dropSavePoint();
|
||||
$tokens->pushSavePoint();
|
||||
}
|
||||
}
|
||||
$tokens->pushSavePoint();
|
||||
$tokens->next();
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END)) {
|
||||
// if we're at EOL, check what's next
|
||||
// if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, ...$endTokens)) {
|
||||
$tokens->rollback();
|
||||
break;
|
||||
}
|
||||
// otherwise if the next is text, continue building the description string
|
||||
$tokens->dropSavePoint();
|
||||
$text .= $tokens->getDetectedNewline() ?? "\n";
|
||||
}
|
||||
if ($savepoint) {
|
||||
$tokens->rollback();
|
||||
$text = rtrim($text, $tokens->getDetectedNewline() ?? "\n");
|
||||
}
|
||||
return new Ast\PhpDoc\PhpDocTextNode(trim($text, " \t"));
|
||||
}
|
||||
private function parseOptionalDescriptionAfterDoctrineTag(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : string
|
||||
{
|
||||
$text = '';
|
||||
while (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
|
||||
$text .= $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END);
|
||||
$endTokens = [Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END];
|
||||
if ($this->textBetweenTagsBelongsToDescription) {
|
||||
$endTokens = [Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END];
|
||||
}
|
||||
$savepoint = \false;
|
||||
// if the next token is EOL, everything below is skipped and empty string is returned
|
||||
while ($this->textBetweenTagsBelongsToDescription || !$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
|
||||
$tmpText = $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, ...$endTokens);
|
||||
$text .= $tmpText;
|
||||
// stop if we're not at EOL - meaning it's the end of PHPDoc
|
||||
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
|
||||
if (!$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
return trim($text . $this->parseText($tokens)->text, " \t");
|
||||
@ -199,15 +235,31 @@ class PhpDocParser
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($this->textBetweenTagsBelongsToDescription) {
|
||||
if (!$savepoint) {
|
||||
$tokens->pushSavePoint();
|
||||
$savepoint = \true;
|
||||
} elseif ($tmpText !== '') {
|
||||
$tokens->dropSavePoint();
|
||||
$tokens->pushSavePoint();
|
||||
}
|
||||
}
|
||||
$tokens->pushSavePoint();
|
||||
$tokens->next();
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END)) {
|
||||
// if we're at EOL, check what's next
|
||||
// if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, ...$endTokens)) {
|
||||
$tokens->rollback();
|
||||
break;
|
||||
}
|
||||
// otherwise if the next is text, continue building the description string
|
||||
$tokens->dropSavePoint();
|
||||
$text .= $tokens->getDetectedNewline() ?? "\n";
|
||||
}
|
||||
if ($savepoint) {
|
||||
$tokens->rollback();
|
||||
$text = rtrim($text, $tokens->getDetectedNewline() ?? "\n");
|
||||
}
|
||||
return trim($text, " \t");
|
||||
}
|
||||
public function parseTag(\PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\PhpDocTagNode
|
||||
|
Loading…
x
Reference in New Issue
Block a user