Updated Rector to commit 376f6cbd4a51290c63a42d77ac9fc9a3a5d0ab67

376f6cbd4a De-duplicate isAnonymous check (#3782)
This commit is contained in:
Tomas Votruba 2023-05-09 19:13:23 +00:00
parent 7ec53f4a70
commit bf29cbeb9e
38 changed files with 111 additions and 117 deletions

View File

@ -337,8 +337,9 @@ final class PHPStanNodeScopeResolver
private function resolveClassOrInterfaceScope($classLike, MutatingScope $mutatingScope, bool $isScopeRefreshing) : MutatingScope
{
$className = $this->resolveClassName($classLike);
$isAnonymous = $this->classAnalyzer->isAnonymousClass($classLike);
// is anonymous class? - not possible to enter it since PHPStan 0.12.33, see https://github.com/phpstan/phpstan-src/commit/e87fb0ec26f9c8552bbeef26a868b1e5d8185e91
if ($classLike instanceof Class_ && $this->classAnalyzer->isAnonymousClass($classLike)) {
if ($classLike instanceof Class_ && $isAnonymous) {
$classReflection = $this->reflectionProvider->getAnonymousClassReflection($classLike, $mutatingScope);
} elseif (!$this->reflectionProvider->hasClass($className)) {
return $mutatingScope;
@ -346,7 +347,7 @@ final class PHPStanNodeScopeResolver
$classReflection = $this->reflectionProvider->getClass($className);
}
// on refresh, remove entered class avoid entering the class again
if ($isScopeRefreshing && $mutatingScope->isInClass() && !$classReflection->isAnonymous()) {
if ($isScopeRefreshing && $mutatingScope->isInClass() && !$isAnonymous) {
$context = $this->privatesAccessor->getPrivateProperty($mutatingScope, 'context');
$this->privatesAccessor->setPrivateProperty($context, 'classReflection', null);
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'e6fd26353fa114ac92ba4b0c9b572f508b850e7f';
public const PACKAGE_VERSION = '376f6cbd4a51290c63a42d77ac9fc9a3a5d0ab67';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-09 18:34:12';
public const RELEASE_DATE = '2023-05-09 19:08:35';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitb4ca30e2c376abfca468e95676dcf6a8::getLoader();
return ComposerAutoloaderInit5e0cc74cd5afe070b0f4c42a0e5dbb58::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitb4ca30e2c376abfca468e95676dcf6a8
class ComposerAutoloaderInit5e0cc74cd5afe070b0f4c42a0e5dbb58
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitb4ca30e2c376abfca468e95676dcf6a8
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitb4ca30e2c376abfca468e95676dcf6a8', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit5e0cc74cd5afe070b0f4c42a0e5dbb58', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitb4ca30e2c376abfca468e95676dcf6a8', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit5e0cc74cd5afe070b0f4c42a0e5dbb58', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit5e0cc74cd5afe070b0f4c42a0e5dbb58::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit5e0cc74cd5afe070b0f4c42a0e5dbb58::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8
class ComposerStaticInit5e0cc74cd5afe070b0f4c42a0e5dbb58
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3113,9 +3113,9 @@ class ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb4ca30e2c376abfca468e95676dcf6a8::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit5e0cc74cd5afe070b0f4c42a0e5dbb58::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5e0cc74cd5afe070b0f4c42a0e5dbb58::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5e0cc74cd5afe070b0f4c42a0e5dbb58::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1991,12 +1991,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "dc4b405aaa7117ffe0ae44c5535607801ee14aae"
"reference": "63d391e70b0c826346929589a519f0a12ca672fb"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/dc4b405aaa7117ffe0ae44c5535607801ee14aae",
"reference": "dc4b405aaa7117ffe0ae44c5535607801ee14aae",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/63d391e70b0c826346929589a519f0a12ca672fb",
"reference": "63d391e70b0c826346929589a519f0a12ca672fb",
"shasum": ""
},
"require": {
@ -2025,7 +2025,7 @@
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
},
"time": "2023-04-17T16:12:29+00:00",
"time": "2023-05-09T18:00:30+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/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 03df9e3'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3209c44'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main dc4b405'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7320d80'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 03df9e3'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3209c44'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 63d391e'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7320d80'));
private function __construct()
{
}

View File

@ -10,7 +10,7 @@ final class ArgumentShiftingFactory
public function removeAllButFirstArgMethodCall(MethodCall $methodCall, string $methodName) : void
{
$methodCall->name = new Identifier($methodName);
foreach (\array_keys($methodCall->args) as $i) {
foreach (\array_keys($methodCall->getArgs()) as $i) {
// keep first arg
if ($i === 0) {
continue;

View File

@ -35,7 +35,7 @@ final class ExpectExceptionCodeFactory
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($methodCall, ['assertSame', 'assertEquals'])) {
return null;
}
$secondArgument = $methodCall->args[1]->value;
$secondArgument = $methodCall->getArgs()[1]->value;
if (!$secondArgument instanceof MethodCall) {
return null;
}

View File

@ -29,7 +29,7 @@ final class ExpectExceptionFactory
if (!$this->testsNodeAnalyzer->isInPHPUnitMethodCallName($methodCall, 'assertInstanceOf')) {
return null;
}
$argumentVariableName = $this->nodeNameResolver->getName($methodCall->args[1]->value);
$argumentVariableName = $this->nodeNameResolver->getName($methodCall->getArgs()[1]->value);
if ($argumentVariableName === null) {
return null;
}
@ -37,6 +37,6 @@ final class ExpectExceptionFactory
if (!$this->nodeNameResolver->isName($variable, $argumentVariableName)) {
return null;
}
return new MethodCall($methodCall->var, 'expectException', [$methodCall->args[0]]);
return new MethodCall($methodCall->var, 'expectException', [$methodCall->getArgs()[0]]);
}
}

View File

@ -42,7 +42,7 @@ final class ExpectExceptionMessageFactory
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($methodCall, ['assertSame', 'assertEquals'])) {
return null;
}
$secondArgument = $methodCall->args[1]->value;
$secondArgument = $methodCall->getArgs()[1]->value;
if (!$secondArgument instanceof MethodCall) {
return null;
}

View File

@ -43,7 +43,7 @@ final class ExpectExceptionMessageRegExpFactory
if (!$this->testsNodeAnalyzer->isInPHPUnitMethodCallName($methodCall, 'assertContains')) {
return null;
}
$secondArgument = $methodCall->args[1]->value;
$secondArgument = $methodCall->getArgs()[1]->value;
if (!$secondArgument instanceof MethodCall) {
return null;
}
@ -56,10 +56,10 @@ final class ExpectExceptionMessageRegExpFactory
}
$this->argumentShiftingFactory->removeAllButFirstArgMethodCall($methodCall, 'expectExceptionMessageRegExp');
// put regex between "#...#" to create match
if ($methodCall->args[0]->value instanceof String_) {
/** @var String_ $oldString */
$oldString = $methodCall->args[0]->value;
$methodCall->args[0]->value = new String_('#' . \preg_quote($oldString->value, '#') . '#');
$firstArg = $methodCall->getArgs()[0];
if ($firstArg->value instanceof String_) {
$oldString = $firstArg->value;
$firstArg->value = new String_('#' . \preg_quote($oldString->value, '#') . '#');
}
return $methodCall;
}

View File

@ -12,7 +12,7 @@ final class ArgumentMover
*/
public function removeFirst($node) : void
{
$methodArguments = $node->args;
$methodArguments = $node->getArgs();
\array_shift($methodArguments);
$node->args = $methodArguments;
}

View File

@ -155,11 +155,11 @@ CODE_SAMPLE
if (!$this->isMethodCallMatch($methodCall, $arrayArgumentToDataProvider)) {
return;
}
if (\count($methodCall->args) !== 1) {
if (\count($methodCall->getArgs()) !== 1) {
throw new ShouldNotHappenException();
}
// resolve value types
$firstArgumentValue = $methodCall->args[0]->value;
$firstArgumentValue = $methodCall->getArgs()[0]->value;
if (!$firstArgumentValue instanceof Array_) {
// nothing we can do
return;
@ -170,7 +170,7 @@ CODE_SAMPLE
if ($dataProviderMethodName === null) {
return;
}
$this->dataProviderClassMethodRecipes[] = new DataProviderClassMethodRecipe($dataProviderMethodName, $methodCall->args);
$this->dataProviderClassMethodRecipes[] = new DataProviderClassMethodRecipe($dataProviderMethodName, $methodCall->getArgs());
$methodCall->args = [];
$paramAndArgs = $this->paramAndArgFromArrayResolver->resolve($firstArgumentValue, $arrayArgumentToDataProvider->getVariableName());
foreach ($paramAndArgs as $paramAndArg) {

View File

@ -7,8 +7,8 @@ use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Foreach_;
use Rector\Core\NodeManipulator\ForeachManipulator;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -17,15 +17,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class SimplifyForeachInstanceOfRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ForeachManipulator
*/
private $foreachManipulator;
public function __construct(ForeachManipulator $foreachManipulator)
{
$this->foreachManipulator = $foreachManipulator;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Simplify unnecessary foreach check of instances', [new CodeSample(<<<'CODE_SAMPLE'
@ -50,30 +41,31 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
/** @var MethodCall|StaticCall|null $matchedNode */
$matchedNode = $this->foreachManipulator->matchOnlyStmt($node, function (Node $node, Foreach_ $foreach) : ?Node {
if (!$node instanceof MethodCall && !$node instanceof StaticCall) {
return null;
}
if (!$this->isName($node->name, 'assertInstanceOf')) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($foreach->valueVar, $node->args[1]->value)) {
return null;
}
return $node;
});
if ($matchedNode === null) {
if (\count($node->stmts) !== 1) {
return null;
}
$onlyStmt = $node->stmts[0];
if (!$onlyStmt instanceof Expression) {
return null;
}
$expr = $onlyStmt->expr;
if (!$expr instanceof MethodCall && !$expr instanceof StaticCall) {
return null;
}
if (!$this->isName($expr->name, 'assertInstanceOf')) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($node->valueVar, $expr->getArgs()[1]->value)) {
return null;
}
// skip if there is a custom message included; it might be per item
if (\count($matchedNode->getArgs()) === 3) {
if (\count($expr->getArgs()) === 3) {
return null;
}
$args = [$matchedNode->args[0], new Arg($node->expr)];
if ($matchedNode instanceof StaticCall) {
return new StaticCall($matchedNode->class, 'assertContainsOnlyInstancesOf', $args);
$newArgs = [$expr->getArgs()[0], new Arg($node->expr)];
if ($expr instanceof StaticCall) {
return new StaticCall($expr->class, 'assertContainsOnlyInstancesOf', $newArgs);
}
return new MethodCall($matchedNode->var, 'assertContainsOnlyInstancesOf', $args);
return new MethodCall($expr->var, 'assertContainsOnlyInstancesOf', $newArgs);
}
}

View File

@ -64,8 +64,8 @@ final class AssertCompareToSpecificMethodRector extends AbstractRector
if (!isset($node->args[1])) {
return null;
}
$firstArgument = $node->args[0];
$secondArgument = $node->args[1];
$firstArgument = $node->getArgs()[0];
$secondArgument = $node->getArgs()[1];
$firstArgumentValue = $firstArgument->value;
$secondArgumentValue = $secondArgument->value;
if ($secondArgumentValue instanceof FuncCall) {
@ -109,7 +109,7 @@ final class AssertCompareToSpecificMethodRector extends AbstractRector
*/
private function moveFunctionArgumentsUp($node, FuncCall $funcCall, Arg $requiredArg) : void
{
$node->args[1] = $funcCall->args[0];
$node->args[1] = $funcCall->getArgs()[0];
$node->args[0] = $requiredArg;
}
}

View File

@ -69,7 +69,7 @@ final class AssertComparisonToSpecificMethodRector extends AbstractRector
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertTrue', 'assertFalse'])) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof BinaryOp) {
return null;
}
@ -96,7 +96,7 @@ final class AssertComparisonToSpecificMethodRector extends AbstractRector
*/
private function changeArgumentsOrder($node) : void
{
$oldArguments = $node->args;
$oldArguments = $node->getArgs();
/** @var BinaryOp $expression */
$expression = $oldArguments[0]->value;
if ($this->isConstantValue($expression->left)) {

View File

@ -117,8 +117,8 @@ CODE_SAMPLE
return $call;
}
$newMethodCall = $this->assertCallFactory->createCallWithName($call, 'assertEqualsIgnoringCase');
$newMethodCall->args[0] = $call->args[0];
$newMethodCall->args[1] = $call->args[1];
$newMethodCall->args[0] = $call->getArgs()[0];
$newMethodCall->args[1] = $call->getArgs()[1];
if (!$this->valueResolver->isValue($args[2]->value, '')) {
$newMethodCall->args[2] = $args[2];
}

View File

@ -56,7 +56,7 @@ final class AssertFalseStrposToContainsRector extends AbstractRector
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethodName)) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if ($firstArgumentValue instanceof StaticCall) {
return null;
}
@ -80,8 +80,8 @@ final class AssertFalseStrposToContainsRector extends AbstractRector
if (!$strposFuncCallNode instanceof FuncCall) {
return null;
}
$firstArgument = $strposFuncCallNode->args[1];
$secondArgument = $strposFuncCallNode->args[0];
$firstArgument = $strposFuncCallNode->getArgs()[1];
$secondArgument = $strposFuncCallNode->getArgs()[0];
unset($oldArguments[0]);
$newArgs = [$firstArgument, $secondArgument];
$node->args = $this->appendArgs($newArgs, $oldArguments);

View File

@ -58,7 +58,7 @@ final class AssertInstanceOfComparisonRector extends AbstractRector
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethodNames)) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof Instanceof_) {
return null;
}
@ -71,7 +71,7 @@ final class AssertInstanceOfComparisonRector extends AbstractRector
*/
private function changeArgumentsOrder($node) : void
{
$oldArguments = $node->args;
$oldArguments = $node->getArgs();
/** @var Instanceof_ $comparison */
$comparison = $oldArguments[0]->value;
$argument = $comparison->expr;

View File

@ -81,7 +81,7 @@ final class AssertIssetToSpecificMethodRector extends AbstractRector
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, [self::ASSERT_TRUE, self::ASSERT_FALSE])) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
// is property access
if (!$firstArgumentValue instanceof Isset_) {
return null;
@ -91,7 +91,7 @@ final class AssertIssetToSpecificMethodRector extends AbstractRector
return null;
}
/** @var Isset_ $issetNode */
$issetNode = $node->args[0]->value;
$issetNode = $node->getArgs()[0]->value;
$issetNodeArg = $issetNode->vars[0];
if ($issetNodeArg instanceof PropertyFetch) {
if ($this->hasMagicIsset($issetNodeArg->var)) {
@ -141,7 +141,7 @@ final class AssertIssetToSpecificMethodRector extends AbstractRector
return null;
}
$this->identifierManipulator->renameNodeWithMap($node, [self::ASSERT_TRUE => 'assertObjectHasAttribute', self::ASSERT_FALSE => 'assertObjectNotHasAttribute']);
$oldArgs = $node->args;
$oldArgs = $node->getArgs();
unset($oldArgs[0]);
$newArgs = $this->nodeFactory->createArgs([new String_($name), $propertyFetch->var]);
$node->args = $this->appendArgs($newArgs, $oldArgs);
@ -153,7 +153,7 @@ final class AssertIssetToSpecificMethodRector extends AbstractRector
private function refactorArrayDimFetchNode($node, ArrayDimFetch $arrayDimFetch) : Node
{
$this->identifierManipulator->renameNodeWithMap($node, [self::ASSERT_TRUE => 'assertArrayHasKey', self::ASSERT_FALSE => 'assertArrayNotHasKey']);
$oldArgs = $node->args;
$oldArgs = $node->getArgs();
unset($oldArgs[0]);
$node->args = \array_merge($this->nodeFactory->createArgs([$arrayDimFetch->dim, $arrayDimFetch->var]), $oldArgs);
return $node;

View File

@ -57,12 +57,12 @@ final class AssertNotOperatorRector extends AbstractRector
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethodNames)) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof BooleanNot) {
return null;
}
$this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP);
$oldArguments = $node->args;
$oldArguments = $node->getArgs();
/** @var BooleanNot $negation */
$negation = $oldArguments[0]->value;
$expression = $negation->expr;

View File

@ -70,19 +70,19 @@ CODE_SAMPLE
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertTrue', 'assertFalse'])) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof FuncCall) {
return null;
}
if (!$this->isName($firstArgumentValue, 'property_exists')) {
return null;
}
$propertyExistsMethodCall = $node->args[0]->value;
$propertyExistsMethodCall = $node->getArgs()[0]->value;
if (!$propertyExistsMethodCall instanceof FuncCall) {
return null;
}
$firstArgument = $propertyExistsMethodCall->args[0];
$secondArgument = $propertyExistsMethodCall->args[1];
$firstArgument = $propertyExistsMethodCall->getArgs()[0];
$secondArgument = $propertyExistsMethodCall->getArgs()[1];
if ($firstArgument->value instanceof Variable) {
$secondArg = new Variable($firstArgument->value->name);
$map = self::RENAME_METHODS_WITH_OBJECT_MAP;
@ -97,7 +97,7 @@ CODE_SAMPLE
}
unset($node->args[0]);
$newArgs = $this->nodeFactory->createArgs([$secondArgument->value->value, $secondArg]);
$node->args = $this->appendArgs($newArgs, $node->args);
$node->args = $this->appendArgs($newArgs, $node->getArgs());
$this->identifierManipulator->renameNodeWithMap($node, $map);
return $node;
}

View File

@ -66,7 +66,7 @@ final class AssertRegExpRector extends AbstractRector
return null;
}
/** @var FuncCall|Node $secondArgumentValue */
$secondArgumentValue = $node->args[1]->value;
$secondArgumentValue = $node->getArgs()[1]->value;
if (!$secondArgumentValue instanceof FuncCall) {
return null;
}
@ -77,7 +77,7 @@ final class AssertRegExpRector extends AbstractRector
if ($oldMethodName === null) {
return null;
}
$oldFirstArgument = $node->args[0]->value;
$oldFirstArgument = $node->getArgs()[0]->value;
$oldCondition = $this->resolveOldCondition($oldFirstArgument);
$this->renameMethod($node, $oldMethodName, $oldCondition);
$this->moveFunctionArgumentsUp($node);
@ -110,11 +110,11 @@ final class AssertRegExpRector extends AbstractRector
*/
private function moveFunctionArgumentsUp($node) : void
{
$oldArguments = $node->args;
$oldArguments = $node->getArgs();
/** @var FuncCall $pregMatchFunction */
$pregMatchFunction = $oldArguments[1]->value;
$regex = $pregMatchFunction->args[0];
$variable = $pregMatchFunction->args[1];
$regex = $pregMatchFunction->getArgs()[0];
$variable = $pregMatchFunction->getArgs()[1];
unset($oldArguments[0], $oldArguments[1]);
$node->args = \array_merge([$regex, $variable], $oldArguments);
}

View File

@ -60,7 +60,7 @@ final class AssertResourceToClosedResourceRector extends AbstractRector
if (!$this->isNames($node->name, $methodNames)) {
return null;
}
if (!isset($node->args[0])) {
if (!isset($node->getArgs()[0])) {
return null;
}
$this->identifierManipulator->renameNodeWithMap($node, self::RENAME_METHODS_MAP);

View File

@ -64,7 +64,7 @@ final class AssertSameBoolNullToSpecificMethodRector extends AbstractRector
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertSame', 'assertNotSame'])) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof ConstFetch) {
return null;
}

View File

@ -74,12 +74,13 @@ CODE_SAMPLE
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertSame', 'assertEqual', 'assertNotSame', 'assertNotEqual'])) {
return null;
}
if ($this->valueResolver->isTrue($node->args[0]->value)) {
$firstArg = $node->getArgs()[0];
if ($this->valueResolver->isTrue($firstArg->value)) {
$this->argumentMover->removeFirst($node);
$node->name = new Identifier('assertTrue');
return $node;
}
if ($this->valueResolver->isFalse($node->args[0]->value)) {
if ($this->valueResolver->isFalse($firstArg->value)) {
$this->argumentMover->removeFirst($node);
$node->name = new Identifier('assertFalse');
return $node;

View File

@ -62,8 +62,7 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractRe
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, $oldMethods)) {
return null;
}
/** @var FuncCall|Node $firstArgumentValue */
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof FuncCall) {
return null;
}
@ -80,11 +79,11 @@ final class AssertTrueFalseInternalTypeToSpecificMethodRector extends AbstractRe
private function moveFunctionArgumentsUp($node) : Node
{
/** @var FuncCall $isFunctionNode */
$isFunctionNode = $node->args[0]->value;
$firstArgumentValue = $isFunctionNode->args[0]->value;
$isFunctionNode = $node->getArgs()[0]->value;
$firstArgumentValue = $isFunctionNode->getArgs()[0]->value;
$isFunctionName = $this->getName($isFunctionNode);
$newArgs = [new Arg(new String_(self::OLD_FUNCTIONS_TO_TYPES[$isFunctionName])), new Arg($firstArgumentValue)];
$oldArguments = $node->args;
$oldArguments = $node->getArgs();
unset($oldArguments[0]);
$node->args = $this->appendArgs($newArgs, $oldArguments);
return $node;

View File

@ -56,7 +56,7 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractRector
if (!isset($node->args[0])) {
return null;
}
$firstArgumentValue = $node->args[0]->value;
$firstArgumentValue = $node->getArgs()[0]->value;
if (!$firstArgumentValue instanceof FuncCall && !$firstArgumentValue instanceof Empty_) {
return null;
}
@ -103,14 +103,14 @@ final class AssertTrueFalseToSpecificMethodRector extends AbstractRector
*/
private function moveFunctionArgumentsUp($node) : void
{
$funcCallOrEmptyNode = $node->args[0]->value;
$funcCallOrEmptyNode = $node->getArgs()[0]->value;
if ($funcCallOrEmptyNode instanceof FuncCall) {
$funcCallOrEmptyNodeName = $this->getName($funcCallOrEmptyNode);
if ($funcCallOrEmptyNodeName === null) {
return;
}
$funcCallOrEmptyNodeArgs = $funcCallOrEmptyNode->args;
$oldArguments = $node->args;
$funcCallOrEmptyNodeArgs = $funcCallOrEmptyNode->getArgs();
$oldArguments = $node->getArgs();
unset($oldArguments[0]);
$node->args = $this->buildNewArguments($funcCallOrEmptyNodeName, $funcCallOrEmptyNodeArgs, $oldArguments);
}

View File

@ -96,10 +96,11 @@ CODE_SAMPLE
*/
private function replaceExceptionWith($node, string $exceptionClass, string $explicitMethod) : ?Node
{
if (!isset($node->args[0])) {
if (!isset($node->getArgs()[0])) {
return null;
}
if (!$this->isClassConstReference($node->args[0]->value, $exceptionClass)) {
$firstArg = $node->getArgs()[0];
if (!$this->isClassConstReference($firstArg->value, $exceptionClass)) {
return null;
}
return $this->assertCallFactory->createCallWithName($node, $explicitMethod);

View File

@ -77,7 +77,7 @@ CODE_SAMPLE
if (\count($node->args) !== 1) {
return null;
}
$onlyArgument = $node->args[0]->value;
$onlyArgument = $node->getArgs()[0]->value;
if (!$this->isMethodCallOnVariableNamed($onlyArgument, 'this', 'any')) {
return null;
}

View File

@ -73,7 +73,7 @@ CODE_SAMPLE
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertContains', 'assertNotContains'])) {
return null;
}
if (!$this->isPossiblyStringType($node->args[1]->value)) {
if (!$this->isPossiblyStringType($node->getArgs()[1]->value)) {
return null;
}
$methodName = $this->getName($node->name);

View File

@ -73,19 +73,17 @@ CODE_SAMPLE
return null;
}
// when second argument is string: do nothing
$secondArgType = $this->getType($node->args[1]->value);
$secondArgType = $this->getType($node->getArgs()[1]->value);
if ($secondArgType instanceof StringType) {
return null;
}
//when less then 5 arguments given: do nothing
if (!isset($node->args[4])) {
return null;
}
if ($node->args[4]->value === null) {
if (!isset($node->getArgs()[4])) {
return null;
}
$fourthArg = $node->getArgs()[4];
//when 5th argument check identity is true: do nothing
if ($this->valueResolver->isValue($node->args[4]->value, \true)) {
if ($this->valueResolver->isValue($fourthArg->value, \true)) {
return null;
}
/* here we search for element of array without identity check and we can replace functions */

View File

@ -73,7 +73,7 @@ CODE_SAMPLE
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertInternalType', 'assertNotInternalType'])) {
return null;
}
$typeNode = $node->args[0]->value;
$typeNode = $node->getArgs()[0]->value;
if (!$typeNode instanceof String_) {
return null;
}

View File

@ -82,7 +82,7 @@ CODE_SAMPLE
if (!$this->isName($methodCall->name, 'equalTo')) {
continue;
}
$node->args[$i] = $methodCall->args[0];
$node->args[$i] = $methodCall->getArgs()[0];
}
return $node;
}

View File

@ -86,7 +86,7 @@ CODE_SAMPLE
}
// narrow args to one
if (\count($node->args) > 1) {
$node->args = [$node->args[0]];
$node->args = [$node->getArgs()[0]];
}
$node->name = new Identifier('createMock');
return $node;

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\PHPUnit\ValueObject;
use PhpParser\Node\Arg;
use RectorPrefix202305\Webmozart\Assert\Assert;
final class DataProviderClassMethodRecipe
{
/**
@ -23,6 +24,7 @@ final class DataProviderClassMethodRecipe
{
$this->methodName = $methodName;
$this->args = $args;
Assert::allIsInstanceOf($args, Arg::class);
}
public function getMethodName() : string
{