mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 668da1d020b596441b274ee6bf9d1ed763f8e43d
668da1d020
[TypeDeclaration] Utilize ClassMethodReturnTypeOverrideGuard on NumericReturnTypeFromStrictScalarReturnsRector (#5155)
This commit is contained in:
parent
251ad8aeef
commit
f25beaaf93
|
@ -23,18 +23,29 @@ use PhpParser\Node\Identifier;
|
|||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\FloatType;
|
||||
use PHPStan\Type\IntegerType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType instanceof Node) {
|
||||
return null;
|
||||
|
@ -75,6 +86,9 @@ CODE_SAMPLE
|
|||
if ($node->stmts === null) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$return = $this->matchRootReturnWithExpr($node);
|
||||
if (!$return instanceof Return_) {
|
||||
return null;
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0eb6000cfce746d9cf714722047a7d824d1f2dac';
|
||||
public const PACKAGE_VERSION = '668da1d020b596441b274ee6bf9d1ed763f8e43d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-10-11 11:45:36';
|
||||
public const RELEASE_DATE = '2023-10-11 22:47:09';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -69,17 +69,17 @@
|
|||
},
|
||||
{
|
||||
"name": "composer\/pcre",
|
||||
"version": "3.1.0",
|
||||
"version_normalized": "3.1.0.0",
|
||||
"version": "3.1.1",
|
||||
"version_normalized": "3.1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/composer\/pcre.git",
|
||||
"reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2"
|
||||
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/4bff79ddd77851fe3cdd11616ed3f92841ba5bd2",
|
||||
"reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2",
|
||||
"url": "https:\/\/api.github.com\/repos\/composer\/pcre\/zipball\/00104306927c7a0919b4ced2aaa6782c1e61a3c9",
|
||||
"reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -90,7 +90,7 @@
|
|||
"phpstan\/phpstan-strict-rules": "^1.1",
|
||||
"symfony\/phpunit-bridge": "^5"
|
||||
},
|
||||
"time": "2022-11-17T09:50:14+00:00",
|
||||
"time": "2023-10-11T07:11:09+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@ -123,7 +123,7 @@
|
|||
],
|
||||
"support": {
|
||||
"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": [
|
||||
{
|
||||
|
@ -1808,12 +1808,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
|
||||
"reference": "fa5d228a045745149ef95a6b1dad7224f131ce4d"
|
||||
"reference": "9baa15ab8d6c83a8df902cf7cb6209df9e76a530"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/fa5d228a045745149ef95a6b1dad7224f131ce4d",
|
||||
"reference": "fa5d228a045745149ef95a6b1dad7224f131ce4d",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/9baa15ab8d6c83a8df902cf7cb6209df9e76a530",
|
||||
"reference": "9baa15ab8d6c83a8df902cf7cb6209df9e76a530",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1843,7 +1843,7 @@
|
|||
"tomasvotruba\/unused-public": "^0.3",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2023-10-10T13:04:59+00:00",
|
||||
"time": "2023-10-11T09:26:32+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
* @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
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
|
||||
// https://github.com/sebastianbergmann/phpunit/issues/4087
|
||||
new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertRegExp', 'assertMatchesRegularExpression'),
|
||||
new MethodCallRename('PHPUnit\\Framework\\MockObject\\Rule\\InvocationOrder', 'getInvocationCount', 'numberOfInvocations'),
|
||||
// https://github.com/sebastianbergmann/phpunit/issues/4090
|
||||
new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertNotRegExp', 'assertDoesNotMatchRegularExpression'),
|
||||
// https://github.com/sebastianbergmann/phpunit/issues/4078
|
||||
|
|
|
@ -55,7 +55,7 @@ final class WithConsecutiveRector extends AbstractRector implements MinPhpVersio
|
|||
}
|
||||
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;
|
||||
|
||||
final class SomeTest extends TestCase
|
||||
|
@ -83,7 +83,7 @@ final class SomeTest extends TestCase
|
|||
$this->personServiceMock->expects($matcher)
|
||||
->method('prepare')
|
||||
->willReturnCallback(function () use ($matcher) {
|
||||
return match ($matcher->getInvocationCount()) {
|
||||
return match ($matcher->numberOfInvocations()) {
|
||||
1 => [1, 2],
|
||||
2 => [3, 4]
|
||||
};
|
||||
|
@ -203,12 +203,12 @@ CODE_SAMPLE
|
|||
}
|
||||
private function createMatch(Variable $matcherVariable, MethodCall $expectsMethodCall) : Match_
|
||||
{
|
||||
$getInvocationCountMethodCall = new MethodCall($matcherVariable, new Identifier('getInvocationCount'));
|
||||
$numberOfInvocationsMethodCall = new MethodCall($matcherVariable, new Identifier('numberOfInvocations'));
|
||||
$matchArms = [];
|
||||
foreach ($expectsMethodCall->getArgs() as $key => $arg) {
|
||||
$matchArms[] = new MatchArm([new LNumber($key + 1)], $arg->value);
|
||||
}
|
||||
return new Match_($getInvocationCountMethodCall, $matchArms);
|
||||
return new Match_($numberOfInvocationsMethodCall, $matchArms);
|
||||
}
|
||||
/**
|
||||
* @return Variable[]
|
||||
|
|
Loading…
Reference in New Issue