mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 975fdf113f
975fdf113f
[DX] Add StmtsAwareInterface to catch node by type (#2269)
This commit is contained in:
parent
5b56a7d2ca
commit
aa0465d388
|
@ -3,6 +3,7 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
|
||||
require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php';
|
||||
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
|
||||
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
|
||||
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php';
|
||||
|
|
|
@ -22,8 +22,8 @@ final class NodeTypeGroup
|
|||
{
|
||||
/**
|
||||
* These nodes have a public $stmts property that can be iterated - based on https://github.com/rectorphp/php-parser-nodes-docs
|
||||
* @todo create a virtual node, getStmts(): array
|
||||
* @var array<class-string<Node>>
|
||||
* @api
|
||||
*/
|
||||
public const STMTS_AWARE = [\PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Stmt\If_::class, \PhpParser\Node\Stmt\Else_::class, \PhpParser\Node\Stmt\ElseIf_::class, \PhpParser\Node\Stmt\Do_::class, \PhpParser\Node\Stmt\Foreach_::class, \PhpParser\Node\Stmt\TryCatch::class, \PhpParser\Node\Stmt\While_::class, \PhpParser\Node\Stmt\For_::class, \PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\Finally_::class, \PhpParser\Node\Stmt\Case_::class, \PhpParser\Node\Stmt\Catch_::class];
|
||||
}
|
||||
|
|
|
@ -12,12 +12,11 @@ use PhpParser\Node\Stmt;
|
|||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\CodeQuality\NodeAnalyzer\VariableDimFetchAssignResolver;
|
||||
use Rector\CodeQuality\NodeTypeGroup;
|
||||
use Rector\CodeQuality\ValueObject\KeyAndExpr;
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20220508\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\InlineArrayReturnAssignRectorTest
|
||||
*/
|
||||
|
@ -60,12 +59,13 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return \Rector\CodeQuality\NodeTypeGroup::STMTS_AWARE;
|
||||
return [\Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface::class];
|
||||
}
|
||||
/**
|
||||
* @param StmtsAwareInterface $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
\RectorPrefix20220508\Webmozart\Assert\Assert::propertyExists($node, 'stmts');
|
||||
/** @var Stmt[]|null $stmts */
|
||||
$stmts = $node->stmts;
|
||||
if ($stmts === null) {
|
||||
return null;
|
||||
|
|
|
@ -17,12 +17,11 @@ use PhpParser\Node\Stmt\Nop;
|
|||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\Node\Stmt\Throw_;
|
||||
use PhpParser\Node\Stmt\TryCatch;
|
||||
use Rector\CodeQuality\NodeTypeGroup;
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20220508\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @changelog https://github.com/phpstan/phpstan/blob/83078fe308a383c618b8c1caec299e5765d9ac82/src/Node/UnreachableStatementNode.php
|
||||
*
|
||||
|
@ -59,11 +58,13 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return \Rector\CodeQuality\NodeTypeGroup::STMTS_AWARE;
|
||||
return [\Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface::class];
|
||||
}
|
||||
/**
|
||||
* @param StmtsAwareInterface $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
\RectorPrefix20220508\Webmozart\Assert\Assert::propertyExists($node, 'stmts');
|
||||
if ($node->stmts === null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -9,13 +9,12 @@ use PhpParser\Node\Expr\BooleanNot;
|
|||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\CodeQuality\NodeTypeGroup;
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
use Rector\Core\NodeManipulator\IfManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\EarlyReturn\NodeTransformer\ConditionInverter;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20220508\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\EarlyReturn\Rector\If_\ChangeNestedIfsToEarlyReturnRector\ChangeNestedIfsToEarlyReturnRectorTest
|
||||
*/
|
||||
|
@ -77,11 +76,13 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return \Rector\CodeQuality\NodeTypeGroup::STMTS_AWARE;
|
||||
return [\Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface::class];
|
||||
}
|
||||
/**
|
||||
* @param StmtsAwareInterface $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
\RectorPrefix20220508\Webmozart\Assert\Assert::propertyExists($node, 'stmts');
|
||||
$stmts = $node->stmts;
|
||||
if ($stmts === null) {
|
||||
return null;
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '5a122e2b821bdf496cb19abc59c3d13c4db7ed7a';
|
||||
public const PACKAGE_VERSION = '975fdf113fab99b6120383211e997da2c820bd0a';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-05-08 13:22:35';
|
||||
public const RELEASE_DATE = '2022-05-08 20:50:37';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\Contract\PhpParser\Node;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt;
|
||||
/**
|
||||
* @property Stmt[]|null $stmts
|
||||
*/
|
||||
interface StmtsAwareInterface extends \PhpParser\Node
|
||||
{
|
||||
}
|
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86::getLoader();
|
||||
return ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520::getLoader();
|
||||
|
|
|
@ -1664,6 +1664,7 @@ return array(
|
|||
'Rector\\Core\\Contract\\Console\\OutputStyleInterface' => $baseDir . '/src/Contract/Console/OutputStyleInterface.php',
|
||||
'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => $baseDir . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php',
|
||||
'Rector\\Core\\Contract\\PhpParser\\NodePrinterInterface' => $baseDir . '/src/Contract/PhpParser/NodePrinterInterface.php',
|
||||
'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => $baseDir . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php',
|
||||
'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => $baseDir . '/src/Contract/Processor/FileProcessorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\AllowEmptyConfigurableRectorInterface' => $baseDir . '/src/Contract/Rector/AllowEmptyConfigurableRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\ConfigurableRectorInterface' => $baseDir . '/src/Contract/Rector/ConfigurableRectorInterface.php',
|
||||
|
@ -2927,6 +2928,7 @@ return array(
|
|||
'Rector\\Symfony\\NodeFactory\\OnLogoutClassMethodFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/OnLogoutClassMethodFactory.php',
|
||||
'Rector\\Symfony\\NodeFactory\\OnSuccessLogoutClassMethodFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/OnSuccessLogoutClassMethodFactory.php',
|
||||
'Rector\\Symfony\\NodeFactory\\ThisRenderFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/ThisRenderFactory.php',
|
||||
'Rector\\Symfony\\NodeFinder\\EmptyReturnNodeFinder' => $vendorDir . '/rector/rector-symfony/src/NodeFinder/EmptyReturnNodeFinder.php',
|
||||
'Rector\\Symfony\\PhpDocNode\\SymfonyRouteTagValueNodeFactory' => $vendorDir . '/rector/rector-symfony/src/PhpDocNode/SymfonyRouteTagValueNodeFactory.php',
|
||||
'Rector\\Symfony\\Printer\\NeighbourClassLikePrinter' => $vendorDir . '/rector/rector-symfony/src/Printer/NeighbourClassLikePrinter.php',
|
||||
'Rector\\Symfony\\Rector\\BinaryOp\\ResponseStatusCodeRector' => $vendorDir . '/rector/rector-symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86
|
||||
class ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3e72a055e0bf2e893f97d40cfd760520::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit3e72a055e0bf2e893f97d40cfd760520::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire3b740c4d66e00d2a36af6430072d5a86($fileIdentifier, $file);
|
||||
composerRequire3e72a055e0bf2e893f97d40cfd760520($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire3b740c4d66e00d2a36af6430072d5a86($fileIdentifier, $file)
|
||||
function composerRequire3e72a055e0bf2e893f97d40cfd760520($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86
|
||||
class ComposerStaticInit3e72a055e0bf2e893f97d40cfd760520
|
||||
{
|
||||
public static $files = array (
|
||||
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
|
||||
|
@ -2033,6 +2033,7 @@ class ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86
|
|||
'Rector\\Core\\Contract\\Console\\OutputStyleInterface' => __DIR__ . '/../..' . '/src/Contract/Console/OutputStyleInterface.php',
|
||||
'Rector\\Core\\Contract\\PHPStan\\Reflection\\TypeToCallReflectionResolver\\TypeToCallReflectionResolverInterface' => __DIR__ . '/../..' . '/src/Contract/PHPStan/Reflection/TypeToCallReflectionResolver/TypeToCallReflectionResolverInterface.php',
|
||||
'Rector\\Core\\Contract\\PhpParser\\NodePrinterInterface' => __DIR__ . '/../..' . '/src/Contract/PhpParser/NodePrinterInterface.php',
|
||||
'Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface' => __DIR__ . '/../..' . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php',
|
||||
'Rector\\Core\\Contract\\Processor\\FileProcessorInterface' => __DIR__ . '/../..' . '/src/Contract/Processor/FileProcessorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\AllowEmptyConfigurableRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/AllowEmptyConfigurableRectorInterface.php',
|
||||
'Rector\\Core\\Contract\\Rector\\ConfigurableRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/ConfigurableRectorInterface.php',
|
||||
|
@ -3296,6 +3297,7 @@ class ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86
|
|||
'Rector\\Symfony\\NodeFactory\\OnLogoutClassMethodFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/OnLogoutClassMethodFactory.php',
|
||||
'Rector\\Symfony\\NodeFactory\\OnSuccessLogoutClassMethodFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/OnSuccessLogoutClassMethodFactory.php',
|
||||
'Rector\\Symfony\\NodeFactory\\ThisRenderFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/ThisRenderFactory.php',
|
||||
'Rector\\Symfony\\NodeFinder\\EmptyReturnNodeFinder' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFinder/EmptyReturnNodeFinder.php',
|
||||
'Rector\\Symfony\\PhpDocNode\\SymfonyRouteTagValueNodeFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/PhpDocNode/SymfonyRouteTagValueNodeFactory.php',
|
||||
'Rector\\Symfony\\Printer\\NeighbourClassLikePrinter' => __DIR__ . '/..' . '/rector/rector-symfony/src/Printer/NeighbourClassLikePrinter.php',
|
||||
'Rector\\Symfony\\Rector\\BinaryOp\\ResponseStatusCodeRector' => __DIR__ . '/..' . '/rector/rector-symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php',
|
||||
|
@ -3882,9 +3884,9 @@ class ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3b740c4d66e00d2a36af6430072d5a86::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3e72a055e0bf2e893f97d40cfd760520::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3e72a055e0bf2e893f97d40cfd760520::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3e72a055e0bf2e893f97d40cfd760520::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -925,7 +925,23 @@
|
|||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.9-dev"
|
||||
}
|
||||
},
|
||||
"patches_applied": [
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-expr-closure-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-finally-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-function-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-do-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-catch-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-trycatch-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-for-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-classmethod-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-else-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-while-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-foreach-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-if-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-case-php.patch",
|
||||
"https:\/\/raw.githubusercontent.com\/rectorphp\/vendor-patches\/main\/patches\/nikic-php-parser-lib-phpparser-node-stmt-elseif-php.patch"
|
||||
]
|
||||
},
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -2628,12 +2644,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "df561edade3487e5527a30c44099e3865821686e"
|
||||
"reference": "a30ba67f3cd083583d6b7b2d69213d2eb8cf1616"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/df561edade3487e5527a30c44099e3865821686e",
|
||||
"reference": "df561edade3487e5527a30c44099e3865821686e",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/a30ba67f3cd083583d6b7b2d69213d2eb8cf1616",
|
||||
"reference": "a30ba67f3cd083583d6b7b2d69213d2eb8cf1616",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2661,7 +2677,7 @@
|
|||
"symplify\/rule-doc-generator": "^10.2",
|
||||
"symplify\/vendor-patches": "^10.2"
|
||||
},
|
||||
"time": "2022-05-06T17:31:13+00:00",
|
||||
"time": "2022-05-08T15:29:30+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,59 @@
|
|||
This file was automatically generated by Composer Patches (https://github.com/cweagans/composer-patches)
|
||||
Patches applied to this directory:
|
||||
|
||||
0
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-expr-closure-php.patch
|
||||
|
||||
|
||||
1
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-finally-php.patch
|
||||
|
||||
|
||||
2
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-function-php.patch
|
||||
|
||||
|
||||
3
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-do-php.patch
|
||||
|
||||
|
||||
4
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-catch-php.patch
|
||||
|
||||
|
||||
5
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-trycatch-php.patch
|
||||
|
||||
|
||||
6
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-for-php.patch
|
||||
|
||||
|
||||
7
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-classmethod-php.patch
|
||||
|
||||
|
||||
8
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-else-php.patch
|
||||
|
||||
|
||||
9
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-while-php.patch
|
||||
|
||||
|
||||
10
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-foreach-php.patch
|
||||
|
||||
|
||||
11
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-if-php.patch
|
||||
|
||||
|
||||
12
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-case-php.patch
|
||||
|
||||
|
||||
13
|
||||
Source: https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-elseif-php.patch
|
||||
|
||||
|
|
@ -6,7 +6,8 @@ namespace PhpParser\Node\Expr;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
class Closure extends \PhpParser\Node\Expr implements \PhpParser\Node\FunctionLike
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Closure extends \PhpParser\Node\Expr implements \PhpParser\Node\FunctionLike, \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var bool Whether the closure is static */
|
||||
public $static;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class Case_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Case_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var null|Node\Expr Condition (null for default) */
|
||||
public $cond;
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace PhpParser\Node\Stmt;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
class Catch_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Catch_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Name[] Types of exceptions to catch */
|
||||
public $types;
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace PhpParser\Node\Stmt;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
class ClassMethod extends \PhpParser\Node\Stmt implements \PhpParser\Node\FunctionLike
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class ClassMethod extends \PhpParser\Node\Stmt implements \PhpParser\Node\FunctionLike, \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var int Flags */
|
||||
public $flags;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class Do_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Do_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Stmt[] Statements */
|
||||
public $stmts;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class ElseIf_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class ElseIf_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Expr Condition */
|
||||
public $cond;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class Else_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Else_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Stmt[] Statements */
|
||||
public $stmts;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class Finally_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Finally_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Stmt[] Statements */
|
||||
public $stmts;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class For_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class For_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Expr[] Init expressions */
|
||||
public $init;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class Foreach_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Foreach_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Expr Expression to iterate */
|
||||
public $expr;
|
||||
|
|
|
@ -5,7 +5,8 @@ namespace PhpParser\Node\Stmt;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
class Function_ extends \PhpParser\Node\Stmt implements \PhpParser\Node\FunctionLike
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class Function_ extends \PhpParser\Node\Stmt implements \PhpParser\Node\FunctionLike, \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var bool Whether function returns by reference */
|
||||
public $byRef;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class If_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class If_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Expr Condition expression */
|
||||
public $cond;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class TryCatch extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class TryCatch extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Stmt[] Statements */
|
||||
public $stmts;
|
||||
|
|
|
@ -4,7 +4,8 @@ declare (strict_types=1);
|
|||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
class While_ extends \PhpParser\Node\Stmt
|
||||
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
|
||||
class While_ extends \PhpParser\Node\Stmt implements \Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface
|
||||
{
|
||||
/** @var Node\Expr Condition */
|
||||
public $cond;
|
||||
|
|
|
@ -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 b59802f'), '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 77c17ba'), '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 784271e'), '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 6d0fcdc'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main eb83b5c'), '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 e544f2a'), '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 0dd840b'), '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 df561ed'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 5abcdf5'));
|
||||
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 b59802f'), '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 77c17ba'), '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 784271e'), '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 6d0fcdc'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main eb83b5c'), '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 e544f2a'), '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 0dd840b'), '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 a30ba67'), 'ssch/typo3-rector' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/ssch/typo3-rector', 'relative_install_path' => '../../../ssch/typo3-rector', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 5abcdf5'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ final class TemplateGuesser
|
|||
$this->bundleClassResolver = $bundleClassResolver;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
public function resolveFromClassMethodNode(\PhpParser\Node\Stmt\ClassMethod $classMethod) : string
|
||||
public function resolveFromClassMethod(\PhpParser\Node\Stmt\ClassMethod $classMethod) : string
|
||||
{
|
||||
$scope = $classMethod->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
|
||||
if (!$scope instanceof \PHPStan\Analyser\Scope) {
|
||||
|
|
|
@ -55,15 +55,15 @@ final class ThisRenderFactory
|
|||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->templateGuesser = $templateGuesser;
|
||||
}
|
||||
public function create(\PhpParser\Node\Stmt\ClassMethod $classMethod, ?\PhpParser\Node\Stmt\Return_ $return, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : \PhpParser\Node\Expr\MethodCall
|
||||
public function create(?\PhpParser\Node\Stmt\Return_ $return, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, \PhpParser\Node\Stmt\ClassMethod $classMethod) : \PhpParser\Node\Expr\MethodCall
|
||||
{
|
||||
$renderArguments = $this->resolveRenderArguments($classMethod, $return, $templateDoctrineAnnotationTagValueNode);
|
||||
$renderArguments = $this->resolveRenderArguments($return, $templateDoctrineAnnotationTagValueNode, $classMethod);
|
||||
return $this->nodeFactory->createMethodCall('this', 'render', $renderArguments);
|
||||
}
|
||||
/**
|
||||
* @return Arg[]
|
||||
*/
|
||||
private function resolveRenderArguments(\PhpParser\Node\Stmt\ClassMethod $classMethod, ?\PhpParser\Node\Stmt\Return_ $return, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : array
|
||||
private function resolveRenderArguments(?\PhpParser\Node\Stmt\Return_ $return, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, \PhpParser\Node\Stmt\ClassMethod $classMethod) : array
|
||||
{
|
||||
$templateNameString = $this->resolveTemplateName($classMethod, $templateDoctrineAnnotationTagValueNode);
|
||||
$arguments = [$templateNameString];
|
||||
|
@ -79,7 +79,7 @@ final class ThisRenderFactory
|
|||
if (\is_string($template)) {
|
||||
return $template;
|
||||
}
|
||||
return $this->templateGuesser->resolveFromClassMethodNode($classMethod);
|
||||
return $this->templateGuesser->resolveFromClassMethod($classMethod);
|
||||
}
|
||||
private function resolveParametersExpr(?\PhpParser\Node\Stmt\Return_ $return, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : ?\PhpParser\Node\Expr
|
||||
{
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Symfony\NodeFinder;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
final class EmptyReturnNodeFinder
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
}
|
||||
public function hasNoOrEmptyReturns(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
|
||||
{
|
||||
/** @var Return_[] $returns */
|
||||
$returns = $this->betterNodeFinder->findInstanceOf($classMethod, \PhpParser\Node\Stmt\Return_::class);
|
||||
if ($returns === []) {
|
||||
return \true;
|
||||
}
|
||||
foreach ($returns as $return) {
|
||||
if ($return->expr instanceof \PhpParser\Node\Expr) {
|
||||
continue;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
|
@ -12,8 +12,10 @@ use PhpParser\Node\Expr\Instanceof_;
|
|||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
|
@ -23,13 +25,17 @@ use PHPStan\Type\Constant\ConstantArrayType;
|
|||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
|
||||
use Rector\CodeQuality\NodeTypeGroup;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Symfony\NodeFactory\ThisRenderFactory;
|
||||
use Rector\Symfony\NodeFinder\EmptyReturnNodeFinder;
|
||||
use Rector\Symfony\TypeAnalyzer\ArrayUnionResponseTypeAnalyzer;
|
||||
use Rector\Symfony\TypeDeclaration\ReturnTypeDeclarationUpdater;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20220508\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see https://github.com/symfony/symfony-docs/pull/12387#discussion_r329551967
|
||||
* @see https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view.html
|
||||
|
@ -43,6 +49,10 @@ final class TemplateAnnotationToThisRenderRector extends \Rector\Core\Rector\Abs
|
|||
* @var class-string
|
||||
*/
|
||||
private const RESPONSE_CLASS = 'Symfony\\Component\\HttpFoundation\\Response';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const TEMPLATE_ANNOTATION_CLASS = 'Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Symfony\TypeAnalyzer\ArrayUnionResponseTypeAnalyzer
|
||||
|
@ -63,12 +73,18 @@ final class TemplateAnnotationToThisRenderRector extends \Rector\Core\Rector\Abs
|
|||
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover
|
||||
*/
|
||||
private $phpDocTagRemover;
|
||||
public function __construct(\Rector\Symfony\TypeAnalyzer\ArrayUnionResponseTypeAnalyzer $arrayUnionResponseTypeAnalyzer, \Rector\Symfony\TypeDeclaration\ReturnTypeDeclarationUpdater $returnTypeDeclarationUpdater, \Rector\Symfony\NodeFactory\ThisRenderFactory $thisRenderFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Symfony\NodeFinder\EmptyReturnNodeFinder
|
||||
*/
|
||||
private $emptyReturnNodeFinder;
|
||||
public function __construct(\Rector\Symfony\TypeAnalyzer\ArrayUnionResponseTypeAnalyzer $arrayUnionResponseTypeAnalyzer, \Rector\Symfony\TypeDeclaration\ReturnTypeDeclarationUpdater $returnTypeDeclarationUpdater, \Rector\Symfony\NodeFactory\ThisRenderFactory $thisRenderFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover, \Rector\Symfony\NodeFinder\EmptyReturnNodeFinder $emptyReturnNodeFinder)
|
||||
{
|
||||
$this->arrayUnionResponseTypeAnalyzer = $arrayUnionResponseTypeAnalyzer;
|
||||
$this->returnTypeDeclarationUpdater = $returnTypeDeclarationUpdater;
|
||||
$this->thisRenderFactory = $thisRenderFactory;
|
||||
$this->phpDocTagRemover = $phpDocTagRemover;
|
||||
$this->emptyReturnNodeFinder = $emptyReturnNodeFinder;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
|
@ -110,7 +126,7 @@ CODE_SAMPLE
|
|||
if ($class->extends !== null) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->hasTemplateAnnotations($class)) {
|
||||
if (!$this->hasClassMethodWithTemplateAnnotation($class)) {
|
||||
return null;
|
||||
}
|
||||
$class->extends = new \PhpParser\Node\Name\FullyQualified('Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController');
|
||||
|
@ -121,19 +137,18 @@ CODE_SAMPLE
|
|||
if (!$classMethod->isPublic()) {
|
||||
return null;
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass('Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template');
|
||||
$doctrineAnnotationTagValueNode = $this->getDoctrineAnnotationTagValueNode($classMethod, self::TEMPLATE_ANNOTATION_CLASS);
|
||||
if (!$doctrineAnnotationTagValueNode instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
|
||||
return null;
|
||||
}
|
||||
$this->refactorClassMethod($classMethod, $doctrineAnnotationTagValueNode);
|
||||
return $classMethod;
|
||||
}
|
||||
private function hasTemplateAnnotations(\PhpParser\Node\Stmt\Class_ $class) : bool
|
||||
private function hasClassMethodWithTemplateAnnotation(\PhpParser\Node\Stmt\Class_ $class) : bool
|
||||
{
|
||||
foreach ($class->getMethods() as $classMethod) {
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
if ($phpDocInfo->hasByAnnotationClass('Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template')) {
|
||||
$templateDoctrineAnnotationTagValueNode = $this->getDoctrineAnnotationTagValueNode($classMethod, self::TEMPLATE_ANNOTATION_CLASS);
|
||||
if ($templateDoctrineAnnotationTagValueNode instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
|
@ -141,40 +156,29 @@ CODE_SAMPLE
|
|||
}
|
||||
private function refactorClassMethod(\PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode) : void
|
||||
{
|
||||
/** @var Return_[] $returns */
|
||||
$returns = $this->findReturnsInCurrentScope((array) $classMethod->stmts);
|
||||
$hasThisRenderOrReturnsResponse = $this->hasLastReturnResponse($classMethod);
|
||||
foreach ($returns as $return) {
|
||||
$this->refactorReturn($return, $classMethod, $templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse);
|
||||
}
|
||||
if ($returns === []) {
|
||||
$thisRenderMethodCall = $this->thisRenderFactory->create($classMethod, null, $templateDoctrineAnnotationTagValueNode);
|
||||
$this->refactorNoReturn($classMethod, $thisRenderMethodCall);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This skips anonymous functions and functions, as their returns doesn't influence current code
|
||||
*
|
||||
* @param Node[] $stmts
|
||||
* @return Return_[]
|
||||
*/
|
||||
private function findReturnsInCurrentScope(array $stmts) : array
|
||||
{
|
||||
$returns = [];
|
||||
$this->traverseNodesWithCallable($stmts, function (\PhpParser\Node $node) use(&$returns) : ?int {
|
||||
if ($node instanceof \PhpParser\Node\Expr\Closure) {
|
||||
$this->traverseNodesWithCallable($classMethod, function (\PhpParser\Node $node) use($templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod) {
|
||||
// keep as similar type
|
||||
if ($node instanceof \PhpParser\Node\Expr\Closure || $node instanceof \PhpParser\Node\Stmt\Function_) {
|
||||
return \PhpParser\NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Stmt\Function_) {
|
||||
return \PhpParser\NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||
}
|
||||
if (!$node instanceof \PhpParser\Node\Stmt\Return_) {
|
||||
if (!$node instanceof \PhpParser\Node\Stmt) {
|
||||
return null;
|
||||
}
|
||||
foreach (\Rector\CodeQuality\NodeTypeGroup::STMTS_AWARE as $stmtsAwareType) {
|
||||
if (!\is_a($node, $stmtsAwareType, \true)) {
|
||||
continue;
|
||||
}
|
||||
$this->refactorStmtsAwareNode($node, $templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod);
|
||||
return null;
|
||||
}
|
||||
$returns[] = $node;
|
||||
return null;
|
||||
});
|
||||
return $returns;
|
||||
if (!$this->emptyReturnNodeFinder->hasNoOrEmptyReturns($classMethod)) {
|
||||
return;
|
||||
}
|
||||
$thisRenderMethodCall = $this->thisRenderFactory->create(null, $templateDoctrineAnnotationTagValueNode, $classMethod);
|
||||
$this->refactorNoReturn($classMethod, $thisRenderMethodCall, $templateDoctrineAnnotationTagValueNode);
|
||||
}
|
||||
private function hasLastReturnResponse(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
|
||||
{
|
||||
|
@ -189,23 +193,31 @@ CODE_SAMPLE
|
|||
$returnType = $this->getType($lastReturn->expr);
|
||||
return $responseObjectType->isSuperTypeOf($returnType)->yes();
|
||||
}
|
||||
private function refactorReturn(\PhpParser\Node\Stmt\Return_ $return, \PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, bool $hasThisRenderOrReturnsResponse) : void
|
||||
private function refactorReturn(\PhpParser\Node\Stmt\Return_ $return, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, bool $hasThisRenderOrReturnsResponse, \PhpParser\Node\Stmt\ClassMethod $classMethod) : void
|
||||
{
|
||||
// nothing we can do
|
||||
if ($return->expr === null) {
|
||||
return;
|
||||
}
|
||||
// create "$this->render('template.file.twig.html', ['key' => 'value']);" method call
|
||||
$thisRenderMethodCall = $this->thisRenderFactory->create($classMethod, $return, $templateDoctrineAnnotationTagValueNode);
|
||||
$this->refactorReturnWithValue($return, $hasThisRenderOrReturnsResponse, $thisRenderMethodCall, $classMethod);
|
||||
$thisRenderMethodCall = $this->thisRenderFactory->create($return, $templateDoctrineAnnotationTagValueNode, $classMethod);
|
||||
$this->refactorReturnWithValue($return, $hasThisRenderOrReturnsResponse, $thisRenderMethodCall, $classMethod, $templateDoctrineAnnotationTagValueNode);
|
||||
}
|
||||
private function refactorNoReturn(\PhpParser\Node\Stmt\ClassMethod $classMethod, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall) : void
|
||||
private function getDoctrineAnnotationTagValueNode(\PhpParser\Node\Stmt\ClassMethod $classMethod, string $class) : ?\Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode
|
||||
{
|
||||
$this->processClassMethodWithoutReturn($classMethod, $thisRenderMethodCall);
|
||||
$this->returnTypeDeclarationUpdater->updateClassMethod($classMethod, self::RESPONSE_CLASS);
|
||||
$this->removeDoctrineAnnotationTagValueNode($classMethod);
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($classMethod);
|
||||
if (!$phpDocInfo instanceof \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo) {
|
||||
return null;
|
||||
}
|
||||
return $phpDocInfo->getByAnnotationClass($class);
|
||||
}
|
||||
private function refactorReturnWithValue(\PhpParser\Node\Stmt\Return_ $return, bool $hasThisRenderOrReturnsResponse, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall, \PhpParser\Node\Stmt\ClassMethod $classMethod) : void
|
||||
private function refactorNoReturn(\PhpParser\Node\Stmt\ClassMethod $classMethod, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
|
||||
{
|
||||
$classMethod->stmts[] = new \PhpParser\Node\Stmt\Return_($thisRenderMethodCall);
|
||||
$this->returnTypeDeclarationUpdater->updateClassMethod($classMethod, self::RESPONSE_CLASS);
|
||||
$this->removeDoctrineAnnotationTagValueNode($classMethod, $doctrineAnnotationTagValueNode);
|
||||
}
|
||||
private function refactorReturnWithValue(\PhpParser\Node\Stmt\Return_ $return, bool $hasThisRenderOrReturnsResponse, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall, \PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
|
||||
{
|
||||
/** @var Expr $lastReturnExpr */
|
||||
$lastReturnExpr = $return->expr;
|
||||
|
@ -222,43 +234,43 @@ CODE_SAMPLE
|
|||
}
|
||||
$isArrayOrResponseType = $this->arrayUnionResponseTypeAnalyzer->isArrayUnionResponseType($returnStaticType, self::RESPONSE_CLASS);
|
||||
if ($isArrayOrResponseType) {
|
||||
$this->processIsArrayOrResponseType($return, $lastReturnExpr, $thisRenderMethodCall);
|
||||
$this->processIsArrayOrResponseType($classMethod, $return, $lastReturnExpr, $thisRenderMethodCall);
|
||||
}
|
||||
// already response
|
||||
$this->removeAnnotationClass($classMethod);
|
||||
$this->removeDoctrineAnnotationTagValueNode($classMethod, $doctrineAnnotationTagValueNode);
|
||||
$this->returnTypeDeclarationUpdater->updateClassMethod($classMethod, self::RESPONSE_CLASS);
|
||||
}
|
||||
private function processClassMethodWithoutReturn(\PhpParser\Node\Stmt\ClassMethod $classMethod, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall) : void
|
||||
{
|
||||
$classMethod->stmts[] = new \PhpParser\Node\Stmt\Return_($thisRenderMethodCall);
|
||||
}
|
||||
private function processIsArrayOrResponseType(\PhpParser\Node\Stmt\Return_ $return, \PhpParser\Node\Expr $returnExpr, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall) : void
|
||||
private function processIsArrayOrResponseType(\PhpParser\Node\Stmt\ClassMethod $classMethod, \PhpParser\Node\Stmt\Return_ $return, \PhpParser\Node\Expr $returnExpr, \PhpParser\Node\Expr\MethodCall $thisRenderMethodCall) : void
|
||||
{
|
||||
$this->removeNode($return);
|
||||
// create instance of Response → return response, or return $this->render
|
||||
$responseVariable = new \PhpParser\Node\Expr\Variable('responseOrData');
|
||||
$assign = new \PhpParser\Node\Expr\Assign($responseVariable, $returnExpr);
|
||||
$assignExpression = new \PhpParser\Node\Stmt\Expression($assign);
|
||||
$if = new \PhpParser\Node\Stmt\If_(new \PhpParser\Node\Expr\Instanceof_($responseVariable, new \PhpParser\Node\Name\FullyQualified(self::RESPONSE_CLASS)));
|
||||
$if->stmts[] = new \PhpParser\Node\Stmt\Return_($responseVariable);
|
||||
$thisRenderMethodCall->args[1] = new \PhpParser\Node\Arg($responseVariable);
|
||||
$returnThisRender = new \PhpParser\Node\Stmt\Return_($thisRenderMethodCall);
|
||||
$this->nodesToAddCollector->addNodesAfterNode([$assign, $if, $returnThisRender], $return);
|
||||
$classMethodStmts = (array) $classMethod->stmts;
|
||||
$classMethod->stmts = \array_merge($classMethodStmts, [$assignExpression, $if, $returnThisRender]);
|
||||
}
|
||||
private function removeDoctrineAnnotationTagValueNode(\PhpParser\Node\Stmt\ClassMethod $classMethod) : void
|
||||
private function removeDoctrineAnnotationTagValueNode(\PhpParser\Node\Stmt\ClassMethod $classMethod, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass('Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template');
|
||||
if (!$doctrineAnnotationTagValueNode instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
|
||||
return;
|
||||
}
|
||||
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $doctrineAnnotationTagValueNode);
|
||||
}
|
||||
private function removeAnnotationClass(\PhpParser\Node\Stmt\ClassMethod $classMethod) : void
|
||||
private function refactorStmtsAwareNode(\PhpParser\Node\Stmt $stmtsAwareStmt, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $templateDoctrineAnnotationTagValueNode, bool $hasThisRenderOrReturnsResponse, \PhpParser\Node\Stmt\ClassMethod $classMethod) : void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass('Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Template');
|
||||
if ($doctrineAnnotationTagValueNode instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
|
||||
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $doctrineAnnotationTagValueNode);
|
||||
\RectorPrefix20220508\Webmozart\Assert\Assert::propertyExists($stmtsAwareStmt, 'stmts');
|
||||
foreach ((array) $stmtsAwareStmt->stmts as $stmt) {
|
||||
if (!$stmt instanceof \PhpParser\Node\Stmt\Return_) {
|
||||
continue;
|
||||
}
|
||||
// just created node, skip it
|
||||
if ($stmt->getAttributes() === []) {
|
||||
return;
|
||||
}
|
||||
$this->refactorReturn($stmt, $templateDoctrineAnnotationTagValueNode, $hasThisRenderOrReturnsResponse, $classMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20220508\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86', false) && !interface_exists('ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86', false) && !trait_exists('ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86', false)) {
|
||||
spl_autoload_call('RectorPrefix20220508\ComposerAutoloaderInit3b740c4d66e00d2a36af6430072d5a86');
|
||||
if (!class_exists('ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520', false) && !interface_exists('ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520', false) && !trait_exists('ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520', false)) {
|
||||
spl_autoload_call('RectorPrefix20220508\ComposerAutoloaderInit3e72a055e0bf2e893f97d40cfd760520');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20220508\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20220508\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire3b740c4d66e00d2a36af6430072d5a86')) {
|
||||
function composerRequire3b740c4d66e00d2a36af6430072d5a86() {
|
||||
return \RectorPrefix20220508\composerRequire3b740c4d66e00d2a36af6430072d5a86(...func_get_args());
|
||||
if (!function_exists('composerRequire3e72a055e0bf2e893f97d40cfd760520')) {
|
||||
function composerRequire3e72a055e0bf2e893f97d40cfd760520() {
|
||||
return \RectorPrefix20220508\composerRequire3e72a055e0bf2e893f97d40cfd760520(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
|
Loading…
Reference in New Issue