Updated Rector to commit 668da1d020b596441b274ee6bf9d1ed763f8e43d

668da1d020 [TypeDeclaration] Utilize ClassMethodReturnTypeOverrideGuard on NumericReturnTypeFromStrictScalarReturnsRector (#5155)
This commit is contained in:
Tomas Votruba 2023-10-11 15:50:01 +00:00
parent 251ad8aeef
commit f25beaaf93
8 changed files with 38 additions and 23 deletions

View File

@ -23,18 +23,29 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Return_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\FloatType; use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType; use PHPStan\Type\IntegerType;
use Rector\Core\Rector\AbstractRector; use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/** /**
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictScalarReturnsRector\NumericReturnTypeFromStrictScalarReturnsRectorTest * @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictScalarReturnsRector\NumericReturnTypeFromStrictScalarReturnsRectorTest
*/ */
final class NumericReturnTypeFromStrictScalarReturnsRector extends AbstractRector implements MinPhpVersionInterface final class NumericReturnTypeFromStrictScalarReturnsRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
{ {
/**
* @readonly
* @var \Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard
*/
private $classMethodReturnTypeOverrideGuard;
public function __construct(ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard)
{
$this->classMethodReturnTypeOverrideGuard = $classMethodReturnTypeOverrideGuard;
}
public function getRuleDefinition() : RuleDefinition public function getRuleDefinition() : RuleDefinition
{ {
return new RuleDefinition('Change numeric return type based on strict returns type operations', [new CodeSample(<<<'CODE_SAMPLE' return new RuleDefinition('Change numeric return type based on strict returns type operations', [new CodeSample(<<<'CODE_SAMPLE'
@ -67,7 +78,7 @@ CODE_SAMPLE
/** /**
* @param ClassMethod|Function_|Closure $node * @param ClassMethod|Function_|Closure $node
*/ */
public function refactor(Node $node) : ?Node public function refactorWithScope(Node $node, Scope $scope) : ?Node
{ {
if ($node->returnType instanceof Node) { if ($node->returnType instanceof Node) {
return null; return null;
@ -75,6 +86,9 @@ CODE_SAMPLE
if ($node->stmts === null) { if ($node->stmts === null) {
return null; return null;
} }
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
return null;
}
$return = $this->matchRootReturnWithExpr($node); $return = $this->matchRootReturnWithExpr($node);
if (!$return instanceof Return_) { if (!$return instanceof Return_) {
return null; return null;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '0eb6000cfce746d9cf714722047a7d824d1f2dac'; public const PACKAGE_VERSION = '668da1d020b596441b274ee6bf9d1ed763f8e43d';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2023-10-11 11:45:36'; public const RELEASE_DATE = '2023-10-11 22:47:09';
/** /**
* @var int * @var int
*/ */

View File

@ -69,17 +69,17 @@
}, },
{ {
"name": "composer\/pcre", "name": "composer\/pcre",
"version": "3.1.0", "version": "3.1.1",
"version_normalized": "3.1.0.0", "version_normalized": "3.1.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https:\/\/github.com\/composer\/pcre.git", "url": "https:\/\/github.com\/composer\/pcre.git",
"reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2" "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/4bff79ddd77851fe3cdd11616ed3f92841ba5bd2", "url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/00104306927c7a0919b4ced2aaa6782c1e61a3c9",
"reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2", "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -90,7 +90,7 @@
"phpstan\/phpstan-strict-rules": "^1.1", "phpstan\/phpstan-strict-rules": "^1.1",
"symfony\/phpunit-bridge": "^5" "symfony\/phpunit-bridge": "^5"
}, },
"time": "2022-11-17T09:50:14+00:00", "time": "2023-10-11T07:11:09+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -123,7 +123,7 @@
], ],
"support": { "support": {
"issues": "https:\/\/github.com\/composer\/pcre\/issues", "issues": "https:\/\/github.com\/composer\/pcre\/issues",
"source": "https:\/\/github.com\/composer\/pcre\/tree\/3.1.0" "source": "https:\/\/github.com\/composer\/pcre\/tree\/3.1.1"
}, },
"funding": [ "funding": [
{ {
@ -1808,12 +1808,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git", "url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "fa5d228a045745149ef95a6b1dad7224f131ce4d" "reference": "9baa15ab8d6c83a8df902cf7cb6209df9e76a530"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/fa5d228a045745149ef95a6b1dad7224f131ce4d", "url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/9baa15ab8d6c83a8df902cf7cb6209df9e76a530",
"reference": "fa5d228a045745149ef95a6b1dad7224f131ce4d", "reference": "9baa15ab8d6c83a8df902cf7cb6209df9e76a530",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1843,7 +1843,7 @@
"tomasvotruba\/unused-public": "^0.3", "tomasvotruba\/unused-public": "^0.3",
"tracy\/tracy": "^2.10" "tracy\/tracy": "^2.10"
}, },
"time": "2023-10-10T13:04:59+00:00", "time": "2023-10-11T09:26:32+00:00",
"default-branch": true, "default-branch": true,
"type": "rector-extension", "type": "rector-extension",
"extra": { "extra": {

File diff suppressed because one or more lines are too long

View File

@ -112,7 +112,7 @@ class Preg
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_UNMATCHED_AS_NULL and PREG_MATCH_OFFSET are always set, no other flags are supported * @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_UNMATCHED_AS_NULL and PREG_MATCH_OFFSET are always set, no other flags are supported
* @return 0|positive-int * @return 0|positive-int
* *
* @phpstan-param array<int|string, list<array{string|null, int<-1, max>}>> $matches * @param-out array<int|string, list<array{string|null, int<-1, max>}>> $matches
*/ */
public static function matchAllWithOffsets(string $pattern, string $subject, ?array &$matches, int $flags = 0, int $offset = 0) : int public static function matchAllWithOffsets(string $pattern, string $subject, ?array &$matches, int $flags = 0, int $offset = 0) : int
{ {

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/ */
final class GeneratedConfig final class GeneratedConfig
{ {
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a846e7f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 850b492'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main fa5d228'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 873458c')); public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a846e7f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 850b492'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 9baa15a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 873458c'));
private function __construct() private function __construct()
{ {
} }

View File

@ -17,6 +17,7 @@ return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
// https://github.com/sebastianbergmann/phpunit/issues/4087 // https://github.com/sebastianbergmann/phpunit/issues/4087
new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertRegExp', 'assertMatchesRegularExpression'), new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertRegExp', 'assertMatchesRegularExpression'),
new MethodCallRename('PHPUnit\\Framework\\MockObject\\Rule\\InvocationOrder', 'getInvocationCount', 'numberOfInvocations'),
// https://github.com/sebastianbergmann/phpunit/issues/4090 // https://github.com/sebastianbergmann/phpunit/issues/4090
new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertNotRegExp', 'assertDoesNotMatchRegularExpression'), new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertNotRegExp', 'assertDoesNotMatchRegularExpression'),
// https://github.com/sebastianbergmann/phpunit/issues/4078 // https://github.com/sebastianbergmann/phpunit/issues/4078

View File

@ -55,7 +55,7 @@ final class WithConsecutiveRector extends AbstractRector implements MinPhpVersio
} }
public function getRuleDefinition() : RuleDefinition public function getRuleDefinition() : RuleDefinition
{ {
return new RuleDefinition('Refactor "withConsecutive()" to ', [new CodeSample(<<<'CODE_SAMPLE' return new RuleDefinition('Refactor deprecated withConsecutive() to willReturnCallback() structure', [new CodeSample(<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase final class SomeTest extends TestCase
@ -83,7 +83,7 @@ final class SomeTest extends TestCase
$this->personServiceMock->expects($matcher) $this->personServiceMock->expects($matcher)
->method('prepare') ->method('prepare')
->willReturnCallback(function () use ($matcher) { ->willReturnCallback(function () use ($matcher) {
return match ($matcher->getInvocationCount()) { return match ($matcher->numberOfInvocations()) {
1 => [1, 2], 1 => [1, 2],
2 => [3, 4] 2 => [3, 4]
}; };
@ -203,12 +203,12 @@ CODE_SAMPLE
} }
private function createMatch(Variable $matcherVariable, MethodCall $expectsMethodCall) : Match_ private function createMatch(Variable $matcherVariable, MethodCall $expectsMethodCall) : Match_
{ {
$getInvocationCountMethodCall = new MethodCall($matcherVariable, new Identifier('getInvocationCount')); $numberOfInvocationsMethodCall = new MethodCall($matcherVariable, new Identifier('numberOfInvocations'));
$matchArms = []; $matchArms = [];
foreach ($expectsMethodCall->getArgs() as $key => $arg) { foreach ($expectsMethodCall->getArgs() as $key => $arg) {
$matchArms[] = new MatchArm([new LNumber($key + 1)], $arg->value); $matchArms[] = new MatchArm([new LNumber($key + 1)], $arg->value);
} }
return new Match_($getInvocationCountMethodCall, $matchArms); return new Match_($numberOfInvocationsMethodCall, $matchArms);
} }
/** /**
* @return Variable[] * @return Variable[]