Skip to content

Commit

Permalink
Updated Rector to commit 6dee862408c55479969b4bc0ba28a1d50d5d2e44
Browse files Browse the repository at this point in the history
rectorphp/rector-src@6dee862 [DeadCode] Skip union docblock param with is_object() native type check on RemoveAlwaysTrueIfConditionRector (#6370)
  • Loading branch information
TomasVotruba committed Oct 10, 2024
1 parent ab28bdf commit c8ccd48
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'fbe17776a98d7364df027debe22a97526595a129';
public const PACKAGE_VERSION = '6dee862408c55479969b4bc0ba28a1d50d5d2e44';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-10-09 18:46:05';
public const RELEASE_DATE = '2024-10-10 15:04:05';
/**
* @var int
*/
Expand Down
4 changes: 4 additions & 0 deletions src/NodeAnalyzer/ExprAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\UnionType;
use Rector\Enum\ObjectReference;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand All @@ -39,6 +40,9 @@ public function isNonTypedFromParam(Expr $expr) : bool
return \true;
}
$type = $scope->getType($expr);
if ($nativeType instanceof ObjectWithoutClassType && !$type instanceof ObjectWithoutClassType) {
return \true;
}
if ($nativeType instanceof UnionType) {
return !$nativeType->equals($type);
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@
'Rector\\PHPUnit\\NodeFactory\\UsedVariablesResolver' => $vendorDir . '/rector/rector-phpunit/src/NodeFactory/UsedVariablesResolver.php',
'Rector\\PHPUnit\\NodeFinder\\DataProviderClassMethodFinder' => $vendorDir . '/rector/rector-phpunit/src/NodeFinder/DataProviderClassMethodFinder.php',
'Rector\\PHPUnit\\NodeFinder\\MethodCallNodeFinder' => $vendorDir . '/rector/rector-phpunit/src/NodeFinder/MethodCallNodeFinder.php',
'Rector\\PHPUnit\\PHPUnit100\\NodeDecorator\\WillReturnPerIfNodeDecorator' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/NodeDecorator/WillReturnPerIfNodeDecorator.php',
'Rector\\PHPUnit\\PHPUnit100\\NodeDecorator\\WillReturnIfNodeDecorator' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/NodeDecorator/WillReturnIfNodeDecorator.php',
'Rector\\PHPUnit\\PHPUnit100\\NodeFactory\\WillReturnCallbackFactory' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/NodeFactory/WillReturnCallbackFactory.php',
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\AddProphecyTraitRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/AddProphecyTraitRector.php',
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\PublicDataProviderClassMethodRector' => $vendorDir . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/PublicDataProviderClassMethodRector.php',
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ class ComposerStaticInit7c12491db1a700dd78980ecb6595c088
'Rector\\PHPUnit\\NodeFactory\\UsedVariablesResolver' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFactory/UsedVariablesResolver.php',
'Rector\\PHPUnit\\NodeFinder\\DataProviderClassMethodFinder' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFinder/DataProviderClassMethodFinder.php',
'Rector\\PHPUnit\\NodeFinder\\MethodCallNodeFinder' => __DIR__ . '/..' . '/rector/rector-phpunit/src/NodeFinder/MethodCallNodeFinder.php',
'Rector\\PHPUnit\\PHPUnit100\\NodeDecorator\\WillReturnPerIfNodeDecorator' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/NodeDecorator/WillReturnPerIfNodeDecorator.php',
'Rector\\PHPUnit\\PHPUnit100\\NodeDecorator\\WillReturnIfNodeDecorator' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/NodeDecorator/WillReturnIfNodeDecorator.php',
'Rector\\PHPUnit\\PHPUnit100\\NodeFactory\\WillReturnCallbackFactory' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/NodeFactory/WillReturnCallbackFactory.php',
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\AddProphecyTraitRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/AddProphecyTraitRector.php',
'Rector\\PHPUnit\\PHPUnit100\\Rector\\Class_\\PublicDataProviderClassMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/rules/PHPUnit100/Rector/Class_/PublicDataProviderClassMethodRector.php',
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1811,12 +1811,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "b5e89b8cac97204f51182d902d05f4e802ae4ab0"
"reference": "08f5f635bfcc10cb29c74dc0645fc7730b9168e2"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/b5e89b8cac97204f51182d902d05f4e802ae4ab0",
"reference": "b5e89b8cac97204f51182d902d05f4e802ae4ab0",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/08f5f635bfcc10cb29c74dc0645fc7730b9168e2",
"reference": "08f5f635bfcc10cb29c74dc0645fc7730b9168e2",
"shasum": ""
},
"require": {
Expand All @@ -1840,7 +1840,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-10-09T08:26:10+00:00",
"time": "2024-10-09T14:04:40+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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 e75008c'), '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 d9cef57'), '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 b5e89b8'), '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 928f117'));
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 e75008c'), '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 d9cef57'), '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 08f5f63'), '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 928f117'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use Rector\PHPUnit\Enum\ConsecutiveVariable;
final class NestedClosureAssertFactory
{
/**
Expand All @@ -36,12 +39,16 @@ public function create(MethodCall $assertMethodCall, int $assertKey) : array
return $this->createAssertSameParameters($identical->left, $assertKey);
}
}
if ($arrowFunction->expr instanceof BooleanNot && $arrowFunction->expr->expr instanceof Empty_) {
return $this->createAssertNotEmpty($assertKey, 'assertNotEmpty');
}
if ($arrowFunction->expr instanceof Empty_) {
return $this->createAssertNotEmpty($assertKey, 'assertEmpty');
}
}
$callbackVariable = new Variable('callback');
$callbackAssign = new Assign($callbackVariable, $callableFirstArg->value);
$stmts = [];
$stmts[] = new Expression($callbackAssign);
$callbackVariable = new Variable('callback');
$stmts = [new Expression($callbackAssign)];
$parametersArrayDimFetch = new ArrayDimFetch(new Variable('parameters'), new LNumber($assertKey));
$callbackFuncCall = new FuncCall($callbackVariable, [new Arg($parametersArrayDimFetch)]);
// add assert true to the callback
Expand All @@ -50,7 +57,7 @@ public function create(MethodCall $assertMethodCall, int $assertKey) : array
return $stmts;
}
/**
* @return Stmt[]
* @return Expression[]
*/
private function createAssertSameParameters(Expr $comparedExpr, int $assertKey) : array
{
Expand All @@ -59,4 +66,13 @@ private function createAssertSameParameters(Expr $comparedExpr, int $assertKey)
$assertSameMethodCall = new MethodCall(new Variable('this'), new Identifier('assertSame'), $args);
return [new Expression($assertSameMethodCall)];
}
/**
* @return Expression[]
*/
private function createAssertNotEmpty(int $assertKey, string $emptyMethodName) : array
{
$arrayDimFetch = new ArrayDimFetch(new Variable(ConsecutiveVariable::PARAMETERS), new LNumber($assertKey));
$assertEmptyMethodCall = new MethodCall(new Variable('this'), new Identifier($emptyMethodName), [new Arg($arrayDimFetch)]);
return [new Expression($assertEmptyMethodCall)];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare (strict_types=1);
namespace Rector\PHPUnit\PHPUnit100\NodeDecorator;

use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
final class WillReturnIfNodeDecorator
{
public function decorate(Closure $callbackClosure, ?MethodCall $willReturnOnConsecutiveMethodCall) : void
{
if (!$willReturnOnConsecutiveMethodCall instanceof MethodCall) {
return;
}
foreach ($callbackClosure->stmts as $key => $stmt) {
if (!$stmt instanceof If_) {
continue;
}
$currentArg = $willReturnOnConsecutiveMethodCall->getArgs()[$key];
$stmt->stmts[] = new Return_($currentArg->value);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Rector\PHPUnit\MethodCallRemover;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\PHPUnit\NodeFinder\MethodCallNodeFinder;
use Rector\PHPUnit\PHPUnit100\NodeDecorator\WillReturnPerIfNodeDecorator;
use Rector\PHPUnit\PHPUnit100\NodeDecorator\WillReturnIfNodeDecorator;
use Rector\PHPUnit\PHPUnit100\NodeFactory\WillReturnCallbackFactory;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -47,9 +47,9 @@ final class WithConsecutiveRector extends AbstractRector
private $willReturnCallbackFactory;
/**
* @readonly
* @var \Rector\PHPUnit\PHPUnit100\NodeDecorator\WillReturnPerIfNodeDecorator
* @var \Rector\PHPUnit\MethodCallRemover
*/
private $willReturnPerIfNodeDecorator;
private $methodCallRemover;
/**
* @readonly
* @var \Rector\PHPUnit\NodeFinder\MethodCallNodeFinder
Expand All @@ -62,17 +62,17 @@ final class WithConsecutiveRector extends AbstractRector
private $expectsMethodCallDecorator;
/**
* @readonly
* @var \Rector\PHPUnit\MethodCallRemover
* @var \Rector\PHPUnit\PHPUnit100\NodeDecorator\WillReturnIfNodeDecorator
*/
private $methodCallRemover;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, WillReturnCallbackFactory $willReturnCallbackFactory, WillReturnPerIfNodeDecorator $willReturnPerIfNodeDecorator, MethodCallNodeFinder $methodCallNodeFinder, \Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\ExpectsMethodCallDecorator $expectsMethodCallDecorator, MethodCallRemover $methodCallRemover)
private $willReturnIfNodeDecorator;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, WillReturnCallbackFactory $willReturnCallbackFactory, MethodCallRemover $methodCallRemover, MethodCallNodeFinder $methodCallNodeFinder, \Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\ExpectsMethodCallDecorator $expectsMethodCallDecorator, WillReturnIfNodeDecorator $willReturnIfNodeDecorator)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->willReturnCallbackFactory = $willReturnCallbackFactory;
$this->willReturnPerIfNodeDecorator = $willReturnPerIfNodeDecorator;
$this->methodCallRemover = $methodCallRemover;
$this->methodCallNodeFinder = $methodCallNodeFinder;
$this->expectsMethodCallDecorator = $expectsMethodCallDecorator;
$this->methodCallRemover = $methodCallRemover;
$this->willReturnIfNodeDecorator = $willReturnIfNodeDecorator;
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -201,7 +201,7 @@ private function refactorToWillReturnCallback(MethodCall $withConsecutiveMethodC
$withConsecutiveMethodCall->args = [new Arg($closure)];
$matcherVariable = new Variable(ConsecutiveVariable::MATCHER);
$matcherAssign = new Assign($matcherVariable, $expectsCall);
$this->willReturnPerIfNodeDecorator->decorate($closure, $willReturnOnConsecutiveMethodCall);
$this->willReturnIfNodeDecorator->decorate($closure, $willReturnOnConsecutiveMethodCall);
return [new Expression($matcherAssign), $expression];
}
private function refactorWithExistingWillReturnCallback(MethodCall $existingWillReturnCallback, MethodCall $withConsecutiveMethodCall, Expression $expression) : Expression
Expand Down

0 comments on commit c8ccd48

Please sign in to comment.