Updated Rector to commit 4bc378bb1846b292946f8c241092a79e863268f7

4bc378bb18 [PHP 8.0] Move more logic to MatchFactory (#2802)
This commit is contained in:
Tomas Votruba 2022-08-19 13:01:36 +00:00
parent 8629ef2977
commit 6b02618a3b
12 changed files with 155 additions and 75 deletions

View File

@ -4,8 +4,17 @@ declare (strict_types=1);
namespace Rector\Php80\NodeFactory;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Match_;
use PhpParser\Node\Expr\Throw_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_ as ThrowsStmt;
use Rector\Php80\Enum\MatchKind;
use Rector\Php80\NodeAnalyzer\MatchSwitchAnalyzer;
use Rector\Php80\ValueObject\CondAndExpr;
use Rector\Php80\ValueObject\MatchResult;
final class MatchFactory
{
/**
@ -13,16 +22,79 @@ final class MatchFactory
* @var \Rector\Php80\NodeFactory\MatchArmsFactory
*/
private $matchArmsFactory;
public function __construct(\Rector\Php80\NodeFactory\MatchArmsFactory $matchArmsFactory)
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\MatchSwitchAnalyzer
*/
private $matchSwitchAnalyzer;
public function __construct(\Rector\Php80\NodeFactory\MatchArmsFactory $matchArmsFactory, MatchSwitchAnalyzer $matchSwitchAnalyzer)
{
$this->matchArmsFactory = $matchArmsFactory;
$this->matchSwitchAnalyzer = $matchSwitchAnalyzer;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
public function createFromCondAndExprs(Expr $condExpr, array $condAndExprs) : Match_
public function createFromCondAndExprs(Expr $condExpr, array $condAndExprs, ?Stmt $nextStmt) : ?MatchResult
{
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
return new Match_($condExpr, $matchArms);
$match = new Match_($condExpr, $matchArms);
// implicit return default after switch
if ($nextStmt instanceof Return_ && $nextStmt->expr instanceof Expr) {
return $this->processImplicitReturnAfterSwitch($match, $condAndExprs, $nextStmt->expr);
}
if ($nextStmt instanceof ThrowsStmt) {
return $this->processImplicitThrowsAfterSwitch($match, $condAndExprs, $nextStmt->expr);
}
return new MatchResult($match, \false);
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function processImplicitReturnAfterSwitch(Match_ $match, array $condAndExprs, Expr $returnExpr) : ?MatchResult
{
if ($this->matchSwitchAnalyzer->hasDefaultValue($match)) {
return new MatchResult($match, \false);
}
$expr = $this->resolveAssignVar($condAndExprs);
if ($expr instanceof ArrayDimFetch) {
return null;
}
$shouldRemoveNextStmt = \false;
if (!$expr instanceof Expr) {
$shouldRemoveNextStmt = \true;
}
$condAndExprs[] = new CondAndExpr([], $returnExpr, MatchKind::RETURN);
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
$wrappedMatch = new Match_($match->cond, $matchArms);
return new MatchResult($wrappedMatch, $shouldRemoveNextStmt);
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function resolveAssignVar(array $condAndExprs) : ?Expr
{
foreach ($condAndExprs as $condAndExpr) {
$expr = $condAndExpr->getExpr();
if (!$expr instanceof Assign) {
continue;
}
return $expr->var;
}
return null;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function processImplicitThrowsAfterSwitch(Match_ $match, array $condAndExprs, Expr $throwExpr) : MatchResult
{
if ($this->matchSwitchAnalyzer->hasDefaultValue($match)) {
return new MatchResult($match, \false);
}
$throw = new Throw_($throwExpr);
$condAndExprs[] = new CondAndExpr([], $throw, MatchKind::RETURN);
$matchArms = $this->matchArmsFactory->createFromCondAndExprs($condAndExprs);
$wrappedMatch = new Match_($match->cond, $matchArms);
return new MatchResult($wrappedMatch, \true);
}
}

View File

@ -5,7 +5,6 @@ namespace Rector\Php80\Rector\Switch_;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Match_;
use PhpParser\Node\Expr\Throw_;
@ -14,7 +13,6 @@ use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\Throw_ as ThrowsStmt;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
@ -24,6 +22,7 @@ use Rector\Php80\NodeAnalyzer\MatchSwitchAnalyzer;
use Rector\Php80\NodeFactory\MatchFactory;
use Rector\Php80\NodeResolver\SwitchExprsResolver;
use Rector\Php80\ValueObject\CondAndExpr;
use Rector\Php80\ValueObject\MatchResult;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -121,13 +120,14 @@ CODE_SAMPLE
continue 2;
}
}
$match = $this->matchFactory->createFromCondAndExprs($stmt->cond, $condAndExprs);
// implicit return default after switch
$match = $this->processImplicitReturnAfterSwitch($match, $condAndExprs, $nextStmt);
if (!$match instanceof Match_) {
$matchResult = $this->matchFactory->createFromCondAndExprs($stmt->cond, $condAndExprs, $nextStmt);
if (!$matchResult instanceof MatchResult) {
continue;
}
$match = $this->processImplicitThrowsAfterSwitch($stmt, $match, $condAndExprs, $nextStmt);
$match = $matchResult->getMatch();
if ($matchResult->shouldRemoveNextStmt()) {
unset($node->stmts[$key + 1]);
}
$assignVar = $this->resolveAssignVar($condAndExprs);
$hasDefaultValue = $this->matchSwitchAnalyzer->hasDefaultValue($match);
if ($assignVar instanceof Expr) {
@ -206,47 +206,6 @@ CODE_SAMPLE
}
return null;
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function processImplicitReturnAfterSwitch(Match_ $match, array $condAndExprs, ?Stmt $nextStmt) : ?Match_
{
if (!$nextStmt instanceof Return_) {
return $match;
}
$returnedExpr = $nextStmt->expr;
if (!$returnedExpr instanceof Expr) {
return $match;
}
if ($this->matchSwitchAnalyzer->hasDefaultValue($match)) {
return $match;
}
$assignVar = $this->resolveAssignVar($condAndExprs);
if ($assignVar instanceof ArrayDimFetch) {
return null;
}
if (!$assignVar instanceof Expr) {
$this->removeNode($nextStmt);
}
$condAndExprs[] = new CondAndExpr([], $returnedExpr, MatchKind::RETURN);
return $this->matchFactory->createFromCondAndExprs($match->cond, $condAndExprs);
}
/**
* @param CondAndExpr[] $condAndExprs
*/
private function processImplicitThrowsAfterSwitch(Switch_ $switch, Match_ $match, array $condAndExprs, ?Stmt $nextStmt) : Match_
{
if (!$nextStmt instanceof ThrowsStmt) {
return $match;
}
if ($this->matchSwitchAnalyzer->hasDefaultValue($match)) {
return $match;
}
$this->removeNode($nextStmt);
$throw = new Throw_($nextStmt->expr);
$condAndExprs[] = new CondAndExpr([], $throw, MatchKind::RETURN);
return $this->matchFactory->createFromCondAndExprs($switch->cond, $condAndExprs);
}
private function isFollowedByReturnWithExprUsage(?\PhpParser\Node\Stmt $nextStmt, Expr $expr) : bool
{
if (!$nextStmt instanceof Return_) {

View File

@ -0,0 +1,32 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\ValueObject;
use PhpParser\Node\Expr\Match_;
final class MatchResult
{
/**
* @readonly
* @var \PhpParser\Node\Expr\Match_
*/
private $match;
/**
* @readonly
* @var bool
*/
private $shouldRemoveNextStmt;
public function __construct(Match_ $match, bool $shouldRemoveNextStmt)
{
$this->match = $match;
$this->shouldRemoveNextStmt = $shouldRemoveNextStmt;
}
public function getMatch() : Match_
{
return $this->match;
}
public function shouldRemoveNextStmt() : bool
{
return $this->shouldRemoveNextStmt;
}
}

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '6712529d24205b4b08e86f8da79876fb0d122c49';
public const PACKAGE_VERSION = '4bc378bb1846b292946f8c241092a79e863268f7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-08-19 14:37:58';
public const RELEASE_DATE = '2022-08-19 14:57:40';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2400,6 +2400,7 @@ return array(
'Rector\\Php80\\ValueObject\\ClassNameAndTagValueNode' => $baseDir . '/rules/Php80/ValueObject/ClassNameAndTagValueNode.php',
'Rector\\Php80\\ValueObject\\CondAndExpr' => $baseDir . '/rules/Php80/ValueObject/CondAndExpr.php',
'Rector\\Php80\\ValueObject\\DoctrineTagAndAnnotationToAttribute' => $baseDir . '/rules/Php80/ValueObject/DoctrineTagAndAnnotationToAttribute.php',
'Rector\\Php80\\ValueObject\\MatchResult' => $baseDir . '/rules/Php80/ValueObject/MatchResult.php',
'Rector\\Php80\\ValueObject\\NestedAnnotationToAttribute' => $baseDir . '/rules/Php80/ValueObject/NestedAnnotationToAttribute.php',
'Rector\\Php80\\ValueObject\\NestedDoctrineTagAndAnnotationToAttribute' => $baseDir . '/rules/Php80/ValueObject/NestedDoctrineTagAndAnnotationToAttribute.php',
'Rector\\Php80\\ValueObject\\PropertyPromotionCandidate' => $baseDir . '/rules/Php80/ValueObject/PropertyPromotionCandidate.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitae68ab1a4f19e6758219b7e98a29a94f
class ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitae68ab1a4f19e6758219b7e98a29a94f
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitae68ab1a4f19e6758219b7e98a29a94f', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitae68ab1a4f19e6758219b7e98a29a94f', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit37acacf548ed5342093e9d3ba7cf411a', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireae68ab1a4f19e6758219b7e98a29a94f($fileIdentifier, $file);
composerRequire37acacf548ed5342093e9d3ba7cf411a($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitae68ab1a4f19e6758219b7e98a29a94f
* @param string $file
* @return void
*/
function composerRequireae68ab1a4f19e6758219b7e98a29a94f($fileIdentifier, $file)
function composerRequire37acacf548ed5342093e9d3ba7cf411a($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 ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f
class ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -2697,6 +2697,7 @@ class ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f
'Rector\\Php80\\ValueObject\\ClassNameAndTagValueNode' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/ClassNameAndTagValueNode.php',
'Rector\\Php80\\ValueObject\\CondAndExpr' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/CondAndExpr.php',
'Rector\\Php80\\ValueObject\\DoctrineTagAndAnnotationToAttribute' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/DoctrineTagAndAnnotationToAttribute.php',
'Rector\\Php80\\ValueObject\\MatchResult' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/MatchResult.php',
'Rector\\Php80\\ValueObject\\NestedAnnotationToAttribute' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/NestedAnnotationToAttribute.php',
'Rector\\Php80\\ValueObject\\NestedDoctrineTagAndAnnotationToAttribute' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/NestedDoctrineTagAndAnnotationToAttribute.php',
'Rector\\Php80\\ValueObject\\PropertyPromotionCandidate' => __DIR__ . '/../..' . '/rules/Php80/ValueObject/PropertyPromotionCandidate.php',
@ -3253,9 +3254,9 @@ class ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitae68ab1a4f19e6758219b7e98a29a94f::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit37acacf548ed5342093e9d3ba7cf411a::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2267,12 +2267,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "3f3aba34db19ace5bbdad2e700679e4b72872a19"
"reference": "20ac2a40e499d7933596f7c9c56d6ac0ab9df95d"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/3f3aba34db19ace5bbdad2e700679e4b72872a19",
"reference": "3f3aba34db19ace5bbdad2e700679e4b72872a19",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/20ac2a40e499d7933596f7c9c56d6ac0ab9df95d",
"reference": "20ac2a40e499d7933596f7c9c56d6ac0ab9df95d",
"shasum": ""
},
"require": {
@ -2301,7 +2301,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-08-18T15:12:58+00:00",
"time": "2022-08-19T12:50:54+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-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c2ec06c'), '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 c63e288'), '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 efc7ddf'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 38440b9'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 20edb95'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3638a66'), '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 0e0e399'), '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 3f3aba3'));
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c2ec06c'), '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 c63e288'), '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 efc7ddf'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 38440b9'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 20edb95'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3638a66'), '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 0e0e399'), '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 20ac2a4'));
private function __construct()
{
}

View File

@ -6,6 +6,7 @@ namespace Rector\Symfony\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
@ -70,10 +71,10 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
return [MethodCall::class, StaticCall::class];
}
/**
* @param MethodCall $node
* @param MethodCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
@ -105,7 +106,11 @@ CODE_SAMPLE
$firstArg = $args[0];
return $this->valueResolver->isValue($firstArg->value, 'Location');
}
private function processAssertResponseStatusCodeSame(MethodCall $methodCall) : ?MethodCall
/**
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $methodCall
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|null
*/
private function processAssertResponseStatusCodeSame($methodCall)
{
if (!$this->isName($methodCall->name, 'assertSame')) {
return null;
@ -131,9 +136,16 @@ CODE_SAMPLE
if ($statusCode === 200) {
return null;
}
if ($methodCall instanceof StaticCall) {
return $this->nodeFactory->createStaticCall('self', 'assertResponseStatusCodeSame', [$methodCall->args[0]]);
}
return $this->nodeFactory->createLocalMethodCall('assertResponseStatusCodeSame', [$methodCall->args[0]]);
}
private function processAssertResponseRedirects(MethodCall $methodCall) : ?MethodCall
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $methodCall
* @return \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|null
*/
private function processAssertResponseRedirects($methodCall)
{
if (!$this->testsNodeAnalyzer->isPHPUnitMethodCallNames($methodCall, ['assertSame'])) {
return null;
@ -144,6 +156,9 @@ CODE_SAMPLE
return null;
}
$expectedUrl = $args[0]->value;
if ($methodCall instanceof StaticCall) {
return $this->nodeFactory->createStaticCall('self', 'assertResponseRedirects', [$expectedUrl]);
}
return $this->nodeFactory->createLocalMethodCall('assertResponseRedirects', [$expectedUrl]);
}
}