Updated Rector to commit 49e323a7e24658e84f5d60fcfde83c4e9c652183

49e323a7e2 [automated] Apply Coding Standard (#6712)
This commit is contained in:
Tomas Votruba 2025-02-02 00:36:03 +00:00
parent 0491c7b5d0
commit b1bcc8782b
8 changed files with 123 additions and 26 deletions

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'e31d712625581a0c2cd12e9e804508814c2c3c61';
public const PACKAGE_VERSION = '49e323a7e24658e84f5d60fcfde83c4e9c652183';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2025-02-01 18:19:51';
public const RELEASE_DATE = '2025-02-02 00:33:37';
/**
* @var int
*/

View File

@ -131,24 +131,6 @@ final class BetterStandardPrinter extends Standard
$content = parent::p($node, $precedence, $lhsPrecedence, $parentFormatPreserved);
return $node->getAttribute(AttributeKey::WRAPPED_IN_PARENTHESES) === \true ? '(' . $content . ')' : $content;
}
private function wrapBinaryOp(Node $node) : void
{
if ($this->exprAnalyzer->isExprWithExprPropertyWrappable($node)) {
$node->expr->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
if (!$node instanceof BinaryOp) {
return;
}
if ($node->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
return;
}
if ($node->left instanceof BinaryOp && $node->left->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
$node->left->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
if ($node->right instanceof BinaryOp && $node->right->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
$node->right->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}
protected function pAttributeGroup(AttributeGroup $attributeGroup) : string
{
$ret = parent::pAttributeGroup($attributeGroup);
@ -358,6 +340,24 @@ final class BetterStandardPrinter extends Standard
$this->wrapAssign($instanceof->expr, $instanceof->class);
return parent::pExpr_Instanceof($instanceof, $precedence, $lhsPrecedence);
}
private function wrapBinaryOp(Node $node) : void
{
if ($this->exprAnalyzer->isExprWithExprPropertyWrappable($node)) {
$node->expr->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
if (!$node instanceof BinaryOp) {
return;
}
if ($node->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
return;
}
if ($node->left instanceof BinaryOp && $node->left->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
$node->left->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
if ($node->right instanceof BinaryOp && $node->right->getAttribute(AttributeKey::ORIGINAL_NODE) instanceof Node) {
$node->right->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}
/**
* ensure left side is assign and right side is just created
*

View File

@ -1852,6 +1852,7 @@ return array(
'Rector\\PHPUnit\\PHPUnit80\\Rector\\MethodCall\\SpecificAssertInternalTypeRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit80/Rector/MethodCall/SpecificAssertInternalTypeRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\Class_\\TestListenerToHooksRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit90/Rector/Class_/TestListenerToHooksRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\MethodCall\\ExplicitPhpErrorApiRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit90/Rector/MethodCall/ExplicitPhpErrorApiRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\MethodCall\\ReplaceAtMethodWithDesiredMatcherRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\MethodCall\\SpecificAssertContainsWithoutIdentityRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit90/Rector/MethodCall/SpecificAssertContainsWithoutIdentityRector.php',
'Rector\\PHPUnit\\PhpDoc\\DataProviderMethodRenamer' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/DataProviderMethodRenamer.php',
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',

View File

@ -2071,6 +2071,7 @@ class ComposerStaticInit3327108c61eea19d09115fa0e353e8ec
'Rector\\PHPUnit\\PHPUnit80\\Rector\\MethodCall\\SpecificAssertInternalTypeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit80/Rector/MethodCall/SpecificAssertInternalTypeRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\Class_\\TestListenerToHooksRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit90/Rector/Class_/TestListenerToHooksRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\MethodCall\\ExplicitPhpErrorApiRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit90/Rector/MethodCall/ExplicitPhpErrorApiRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\MethodCall\\ReplaceAtMethodWithDesiredMatcherRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php',
'Rector\\PHPUnit\\PHPUnit90\\Rector\\MethodCall\\SpecificAssertContainsWithoutIdentityRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit90/Rector/MethodCall/SpecificAssertContainsWithoutIdentityRector.php',
'Rector\\PHPUnit\\PhpDoc\\DataProviderMethodRenamer' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/DataProviderMethodRenamer.php',
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',

View File

@ -1804,12 +1804,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "61f5874d64467a17b9c88529077a9c22d718f0eb"
"reference": "e991afeb652ff51a2b2f7eeb869022c0c4fd549f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/61f5874d64467a17b9c88529077a9c22d718f0eb",
"reference": "61f5874d64467a17b9c88529077a9c22d718f0eb",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/e991afeb652ff51a2b2f7eeb869022c0c4fd549f",
"reference": "e991afeb652ff51a2b2f7eeb869022c0c4fd549f",
"shasum": ""
},
"require": {
@ -1830,7 +1830,7 @@
"tomasvotruba\/class-leak": "^1.2",
"tracy\/tracy": "^2.10"
},
"time": "2025-01-31T14:02:02+00:00",
"time": "2025-02-01T20:07:07+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -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 ceda7a4'), '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 6dba109'), '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 61f5874'), '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 4661c01'));
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 ceda7a4'), '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 6dba109'), '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 e991afe'), '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 4661c01'));
private function __construct()
{
}

View File

@ -0,0 +1,95 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\PHPUnit90\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\Int_;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\PHPUnit90\Rector\MethodCall\ReplaceAtMethodWithDesiredMatcherRector\ReplaceAtMethodWithDesiredMatcherRectorTest
*/
final class ReplaceAtMethodWithDesiredMatcherRector extends AbstractRector
{
/**
* @readonly
*/
private TestsNodeAnalyzer $testsNodeAnalyzer;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace at() method call with desired matcher', [new CodeSample(<<<'CODE_SAMPLE'
$mock->expects($this->at(0))
->method('foo')
->willReturn('1');
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$mock->expects($this->never())
->method('foo')
->willReturn('1');
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node) : ?\PhpParser\Node\Expr\MethodCall
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
if ($node->var instanceof MethodCall && ($arg = $this->findAtMethodCall($node->var))) {
$this->replaceWithDesiredMatcher($arg);
}
return null;
}
private function findAtMethodCall(MethodCall $methodCall) : ?Arg
{
foreach ($methodCall->getArgs() as $arg) {
if ($arg->value instanceof MethodCall && $arg->value->name instanceof Identifier && $arg->value->name->toString() === 'at') {
return $arg;
}
}
if ($methodCall->var instanceof MethodCall) {
$this->findAtMethodCall($methodCall->var);
}
return null;
}
private function replaceWithDesiredMatcher(Arg $arg) : void
{
if (!$arg->value instanceof MethodCall) {
return;
}
foreach ($arg->value->getArgs() as $item) {
if ($item->value instanceof Int_) {
$count = $item->value->value;
}
}
if (!isset($count)) {
return;
}
if ($count === 0) {
$arg->value = new MethodCall($arg->value->var, 'never');
} elseif ($count === 1) {
$arg->value = new MethodCall($arg->value->var, 'once');
} elseif ($count > 1) {
$arg->value = new MethodCall($arg->value->var, 'exactly', [new Arg(new Int_($count))]);
}
}
}