mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit 74f6b181e82f191c1e471d446a029a06dff16619
74f6b181e8
[DX] Remove upgrade RectorConfig set, as last 2 version use only PHP (#2852)
This commit is contained in:
parent
5edd3689a8
commit
785f5e3b06
|
@ -34,7 +34,7 @@ By [buying a book](https://leanpub.com/rector-the-power-of-automated-refactoring
|
|||
|
||||
## Documentation
|
||||
|
||||
- [Explore 400+ Rector Rules](/docs/rector_rules_overview.md)
|
||||
- [Explore Rector Rules](/docs/rector_rules_overview.md)
|
||||
- [How to Ignore Rule or Paths](/docs/how_to_ignore_rule_or_paths.md)
|
||||
- [Static Reflection and Autoload](/docs/static_reflection_and_autoload.md)
|
||||
- [How to Configure Rule](/docs/how_to_configure_rules.md)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202208;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\DogFood\Rector\Closure\UpgradeRectorConfigRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rule(UpgradeRectorConfigRector::class);
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
# 401 Rules Overview
|
||||
# 400 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -18,8 +18,6 @@
|
|||
|
||||
- [DependencyInjection](#dependencyinjection) (2)
|
||||
|
||||
- [DogFood](#dogfood) (1)
|
||||
|
||||
- [EarlyReturn](#earlyreturn) (11)
|
||||
|
||||
- [MysqlToMysqli](#mysqltomysqli) (4)
|
||||
|
@ -3773,36 +3771,6 @@ return static function (RectorConfig $rectorConfig): void {
|
|||
|
||||
<br>
|
||||
|
||||
## DogFood
|
||||
|
||||
### UpgradeRectorConfigRector
|
||||
|
||||
Upgrade rector.php config to use of RectorConfig
|
||||
|
||||
- class: [`Rector\DogFood\Rector\Closure\UpgradeRectorConfigRector`](../rules/DogFood/Rector/Closure/UpgradeRectorConfigRector.php)
|
||||
|
||||
```diff
|
||||
-use Rector\Core\Configuration\Option;
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
-use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
+use Rector\Config\RectorConfig;
|
||||
|
||||
-return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
- $parameters = $containerConfigurator->parameters();
|
||||
- $parameters->set(Option::PARALLEL, true);
|
||||
- $parameters->set(Option::AUTO_IMPORT_NAMES, true);
|
||||
+return static function (RectorConfig $rectorConfig): void {
|
||||
+ $rectorConfig->parallel();
|
||||
+ $rectorConfig->importNames();
|
||||
|
||||
- $services = $containerConfigurator->services();
|
||||
- $services->set(TypedPropertyRector::class);
|
||||
+ $rectorConfig->rule(TypedPropertyRector::class);
|
||||
};
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## EarlyReturn
|
||||
|
||||
### ChangeAndIfToEarlyReturnRector
|
||||
|
|
|
@ -3,65 +3,26 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Defluent\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Name;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
/**
|
||||
* Utils for chain of MethodCall Node:
|
||||
* "$this->methodCall()->chainedMethodCall()"
|
||||
*/
|
||||
final class FluentChainMethodCallNodeAnalyzer
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver)
|
||||
public function resolveRootMethodCall(MethodCall $methodCall) : ?MethodCall
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function collectMethodCallNamesInChain(MethodCall $desiredMethodCall) : array
|
||||
{
|
||||
$methodCalls = $this->collectAllMethodCallsInChain($desiredMethodCall);
|
||||
$methodNames = [];
|
||||
foreach ($methodCalls as $methodCall) {
|
||||
$methodName = $this->nodeNameResolver->getName($methodCall->name);
|
||||
if ($methodName === null) {
|
||||
continue;
|
||||
}
|
||||
$methodNames[] = $methodName;
|
||||
$callerNode = $methodCall->var;
|
||||
while ($callerNode instanceof MethodCall && $callerNode->var instanceof MethodCall) {
|
||||
$callerNode = $callerNode->var;
|
||||
}
|
||||
return $methodNames;
|
||||
}
|
||||
/**
|
||||
* @return MethodCall[]
|
||||
*/
|
||||
public function collectAllMethodCallsInChain(MethodCall $methodCall) : array
|
||||
{
|
||||
$chainMethodCalls = [$methodCall];
|
||||
// traverse up
|
||||
$currentNode = $methodCall->var;
|
||||
while ($currentNode instanceof MethodCall) {
|
||||
$chainMethodCalls[] = $currentNode;
|
||||
$currentNode = $currentNode->var;
|
||||
if ($callerNode instanceof MethodCall) {
|
||||
return $callerNode;
|
||||
}
|
||||
// traverse down
|
||||
if (\count($chainMethodCalls) === 1) {
|
||||
$currentNode = $methodCall->getAttribute(AttributeKey::PARENT_NODE);
|
||||
while ($currentNode instanceof MethodCall) {
|
||||
$chainMethodCalls[] = $currentNode;
|
||||
$currentNode = $currentNode->getAttribute(AttributeKey::PARENT_NODE);
|
||||
}
|
||||
}
|
||||
return $chainMethodCalls;
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return \PhpParser\Node\Expr|\PhpParser\Node\Name
|
||||
|
@ -74,15 +35,4 @@ final class FluentChainMethodCallNodeAnalyzer
|
|||
}
|
||||
return $callerNode;
|
||||
}
|
||||
public function resolveRootMethodCall(MethodCall $methodCall) : ?MethodCall
|
||||
{
|
||||
$callerNode = $methodCall->var;
|
||||
while ($callerNode instanceof MethodCall && $callerNode->var instanceof MethodCall) {
|
||||
$callerNode = $callerNode->var;
|
||||
}
|
||||
if ($callerNode instanceof MethodCall) {
|
||||
return $callerNode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeFinder;
|
||||
/**
|
||||
* @todo remove after https://github.com/nikic/PHP-Parser/pull/869 is released
|
||||
* @api
|
||||
*/
|
||||
final class TypeAwareNodeFinder
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PhpParser\NodeFinder
|
||||
*/
|
||||
private $nodeFinder;
|
||||
public function __construct()
|
||||
{
|
||||
// to avoid duplicated services on inject
|
||||
$this->nodeFinder = new NodeFinder();
|
||||
}
|
||||
/**
|
||||
* @template TNode as Node
|
||||
*
|
||||
* @param mixed[]|\PhpParser\Node $nodes
|
||||
* @param class-string<TNode> $type
|
||||
* @return TNode|null
|
||||
*/
|
||||
public function findFirstInstanceOf($nodes, string $type) : ?Node
|
||||
{
|
||||
return $this->nodeFinder->findFirstInstanceOf($nodes, $type);
|
||||
}
|
||||
/**
|
||||
* @template TNode as Node
|
||||
*
|
||||
* @param mixed[]|\PhpParser\Node $nodes
|
||||
* @param class-string<TNode> $type
|
||||
* @return TNode[]
|
||||
*/
|
||||
public function findInstanceOf($nodes, string $type) : array
|
||||
{
|
||||
return $this->nodeFinder->findInstanceOf($nodes, $type);
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\Class_;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class ClassBuilder extends Class_
|
||||
{
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\Method;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class MethodBuilder extends Method
|
||||
{
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\Namespace_;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class NamespaceBuilder extends Namespace_
|
||||
{
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\Param;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class ParamBuilder extends Param
|
||||
{
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\Property;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class PropertyBuilder extends Property
|
||||
{
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\TraitUse;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class TraitUseBuilder extends TraitUse
|
||||
{
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\PhpDocParser\ValueObject\NodeBuilder;
|
||||
|
||||
use PhpParser\Builder\Use_;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Use_ as UseStmt;
|
||||
/**
|
||||
* @api
|
||||
* Fixed duplicated naming in php-parser and prevents confusion
|
||||
*/
|
||||
final class UseBuilder extends Use_
|
||||
{
|
||||
/**
|
||||
* @param \PhpParser\Node\Name|string $name
|
||||
*/
|
||||
public function __construct($name, int $type = UseStmt::TYPE_NORMAL)
|
||||
{
|
||||
parent::__construct($name, $type);
|
||||
}
|
||||
}
|
|
@ -113,8 +113,4 @@ final class SetList implements SetListInterface
|
|||
* @var string
|
||||
*/
|
||||
public const EARLY_RETURN = __DIR__ . '/../../../config/set/early-return.php';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RECTOR_CONFIG = __DIR__ . '/../../../config/set/rector-config.php';
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DogFood\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class ContainerConfiguratorCallAnalyzer
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
|
||||
*/
|
||||
private $valueResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(ValueResolver $valueResolver, NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->valueResolver = $valueResolver;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
public function isMethodCallWithServicesSetConfiguredRectorRule(MethodCall $methodCall) : bool
|
||||
{
|
||||
return $this->nodeNameResolver->isName($methodCall->name, 'configure');
|
||||
}
|
||||
public function isMethodCallWithServicesSetRectorRule(MethodCall $methodCall) : bool
|
||||
{
|
||||
if (!$this->isMethodCallNamed($methodCall, 'services', 'set')) {
|
||||
return \false;
|
||||
}
|
||||
$firstArg = $methodCall->getArgs()[0];
|
||||
$serviceClass = $this->valueResolver->getValue($firstArg->value);
|
||||
if (!\is_string($serviceClass)) {
|
||||
return \false;
|
||||
}
|
||||
return \is_a($serviceClass, RectorInterface::class, \true);
|
||||
}
|
||||
public function isMethodCallNamed(MethodCall $methodCall, string $variableName, string $methodName) : bool
|
||||
{
|
||||
if (!$this->nodeNameResolver->isName($methodCall->var, $variableName)) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeNameResolver->isName($methodCall->name, $methodName);
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DogFood\NodeManipulator;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNextNodeAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class ContainerConfiguratorEmptyAssignRemover
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\NodeAnalyzer\ExprUsedInNextNodeAnalyzer
|
||||
*/
|
||||
private $exprUsedInNextNodeAnalyzer;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, ExprUsedInNextNodeAnalyzer $exprUsedInNextNodeAnalyzer)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->exprUsedInNextNodeAnalyzer = $exprUsedInNextNodeAnalyzer;
|
||||
}
|
||||
public function removeFromClosure(Closure $closure) : void
|
||||
{
|
||||
foreach ($closure->getStmts() as $key => $stmt) {
|
||||
if (!$this->isHelperAssign($stmt)) {
|
||||
continue;
|
||||
}
|
||||
/** @var Expression $expression */
|
||||
$expression = $closure->stmts[$key];
|
||||
/** @var Assign $assign */
|
||||
$assign = $expression->expr;
|
||||
/** @var Expr $var */
|
||||
$var = $assign->var;
|
||||
if ($this->exprUsedInNextNodeAnalyzer->isUsed($var)) {
|
||||
continue;
|
||||
}
|
||||
unset($closure->stmts[$key]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove helper methods calls like:
|
||||
* $services = $containerConfigurator->services();
|
||||
* $parameters = $containerConfigurator->parameters();
|
||||
*/
|
||||
private function isHelperAssign(Stmt $stmt) : bool
|
||||
{
|
||||
if (!$stmt instanceof Expression) {
|
||||
return \false;
|
||||
}
|
||||
$expression = $stmt->expr;
|
||||
if (!$expression instanceof Assign) {
|
||||
return \false;
|
||||
}
|
||||
if (!$expression->expr instanceof MethodCall) {
|
||||
return \false;
|
||||
}
|
||||
$methodCall = $expression->expr;
|
||||
return $this->nodeNameResolver->isNames($methodCall->name, ['parameters', 'services']);
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DogFood\NodeManipulator;
|
||||
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class ContainerConfiguratorImportsMerger
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const RECTOR_CONFIG_VARIABLE = 'rectorConfig';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, NodeFactory $nodeFactory)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
public function merge(Closure $closure) : void
|
||||
{
|
||||
$setConstantFetches = [];
|
||||
$lastImportKey = null;
|
||||
foreach ($closure->getStmts() as $key => $stmt) {
|
||||
if (!$stmt instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
$expr = $stmt->expr;
|
||||
if (!$expr instanceof MethodCall) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($expr->name, 'import')) {
|
||||
continue;
|
||||
}
|
||||
$importArg = $expr->getArgs();
|
||||
$argValue = $importArg[0]->value;
|
||||
if (!$argValue instanceof ClassConstFetch) {
|
||||
continue;
|
||||
}
|
||||
$setConstantFetches[] = $argValue;
|
||||
unset($closure->stmts[$key]);
|
||||
$lastImportKey = $key;
|
||||
}
|
||||
if ($setConstantFetches === []) {
|
||||
return;
|
||||
}
|
||||
$args = $this->nodeFactory->createArgs([$setConstantFetches]);
|
||||
$setsMethodCall = new MethodCall(new Variable(self::RECTOR_CONFIG_VARIABLE), 'sets', $args);
|
||||
$closure->stmts[$lastImportKey] = new Expression($setsMethodCall);
|
||||
\ksort($closure->stmts);
|
||||
}
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DogFood\Rector\Closure;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Param;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
|
||||
use Rector\DogFood\NodeAnalyzer\ContainerConfiguratorCallAnalyzer;
|
||||
use Rector\DogFood\NodeManipulator\ContainerConfiguratorEmptyAssignRemover;
|
||||
use Rector\DogFood\NodeManipulator\ContainerConfiguratorImportsMerger;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\DogFood\Rector\Closure\UpgradeRectorConfigRector\UpgradeRectorConfigRectorTest
|
||||
*/
|
||||
final class UpgradeRectorConfigRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const PARAMETER_NAME_TO_METHOD_CALL_MAP = [Option::PATHS => 'paths', Option::SKIP => 'skip', Option::AUTOLOAD_PATHS => 'autoloadPaths', Option::BOOTSTRAP_FILES => 'bootstrapFiles', Option::IMPORT_SHORT_CLASSES => 'importShortClasses', Option::AUTO_IMPORT_NAMES => 'importNames', Option::PARALLEL => 'parallel', Option::PHPSTAN_FOR_RECTOR_PATH => 'phpstanConfig', Option::PHP_VERSION_FEATURES => 'phpVersion', Option::CACHE_CLASS => 'cacheClass', Option::CACHE_DIR => 'cacheDirectory', Option::NESTED_CHAIN_METHOD_CALL_LIMIT => 'nestedChainMethodCallLimit', Option::FILE_EXTENSIONS => 'fileExtensions', Option::SYMFONY_CONTAINER_PHP_PATH_PARAMETER => 'symfonyContainerPhp', Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER => 'symfonyContainerXml'];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const RECTOR_CONFIG_VARIABLE = 'rectorConfig';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const RECTOR_CONFIG_CLASS = 'Rector\\Config\\RectorConfig';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const PARAMETERS_VARIABLE = 'parameters';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const CONTAINER_CONFIGURATOR_CLASS = 'Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ContainerConfigurator';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const SERVICE_CONFIGURATOR_CLASS = 'Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ServicesConfigurator';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DogFood\NodeAnalyzer\ContainerConfiguratorCallAnalyzer
|
||||
*/
|
||||
private $containerConfiguratorCallAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DogFood\NodeManipulator\ContainerConfiguratorEmptyAssignRemover
|
||||
*/
|
||||
private $containerConfiguratorEmptyAssignRemover;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DogFood\NodeManipulator\ContainerConfiguratorImportsMerger
|
||||
*/
|
||||
private $containerConfiguratorImportsMerger;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer
|
||||
*/
|
||||
private $fluentChainMethodCallNodeAnalyzer;
|
||||
public function __construct(ContainerConfiguratorCallAnalyzer $containerConfiguratorCallAnalyzer, ContainerConfiguratorEmptyAssignRemover $containerConfiguratorEmptyAssignRemover, ContainerConfiguratorImportsMerger $containerConfiguratorImportsMerger, FluentChainMethodCallNodeAnalyzer $fluentChainMethodCallNodeAnalyzer)
|
||||
{
|
||||
$this->containerConfiguratorCallAnalyzer = $containerConfiguratorCallAnalyzer;
|
||||
$this->containerConfiguratorEmptyAssignRemover = $containerConfiguratorEmptyAssignRemover;
|
||||
$this->containerConfiguratorImportsMerger = $containerConfiguratorImportsMerger;
|
||||
$this->fluentChainMethodCallNodeAnalyzer = $fluentChainMethodCallNodeAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Upgrade rector.php config to use of RectorConfig', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
$parameters->set(Option::PARALLEL, true);
|
||||
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
|
||||
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(TypedPropertyRector::class);
|
||||
};
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Rector\Php74\Rector\Property\TypedPropertyRector;
|
||||
use Rector\Config\RectorConfig;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->parallel();
|
||||
$rectorConfig->importNames();
|
||||
|
||||
$rectorConfig->rule(TypedPropertyRector::class);
|
||||
};
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Closure::class];
|
||||
}
|
||||
/**
|
||||
* @param Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->isConfigClosure($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->updateClosureParam($node);
|
||||
// 1. change import of sets to single sets() method call
|
||||
$this->containerConfiguratorImportsMerger->merge($node);
|
||||
$this->traverseNodesWithCallable($node->getStmts(), function (Node $node) : ?Node {
|
||||
if ($node instanceof Variable && $this->isName($node, 'containerConfigurator')) {
|
||||
return new Variable(self::RECTOR_CONFIG_VARIABLE);
|
||||
}
|
||||
// 2. call on rule
|
||||
if ($node instanceof MethodCall) {
|
||||
$nodeVarType = $this->nodeTypeResolver->getType($node->var);
|
||||
if ($nodeVarType instanceof FullyQualifiedObjectType && $nodeVarType->getClassName() === self::SERVICE_CONFIGURATOR_CLASS) {
|
||||
if ($this->isFoundFluentServiceCall($node)) {
|
||||
return null;
|
||||
}
|
||||
$isPossiblyServiceDefinition = (bool) $this->betterNodeFinder->findFirstPrevious($node, function (Node $node) : bool {
|
||||
return $this->isFoundFluentServiceCall($node);
|
||||
});
|
||||
if ($isPossiblyServiceDefinition) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if ($this->containerConfiguratorCallAnalyzer->isMethodCallWithServicesSetConfiguredRectorRule($node)) {
|
||||
return $this->refactorConfigureRuleMethodCall($node);
|
||||
}
|
||||
// look for "$services->set(SomeRector::Class)"
|
||||
if ($this->containerConfiguratorCallAnalyzer->isMethodCallWithServicesSetRectorRule($node)) {
|
||||
$node->var = new Variable(self::RECTOR_CONFIG_VARIABLE);
|
||||
$node->name = new Identifier('rule');
|
||||
return $node;
|
||||
}
|
||||
if ($this->containerConfiguratorCallAnalyzer->isMethodCallNamed($node, self::PARAMETERS_VARIABLE, 'set')) {
|
||||
return $this->refactorParameterName($node);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
$this->containerConfiguratorEmptyAssignRemover->removeFromClosure($node);
|
||||
return $node;
|
||||
}
|
||||
public function updateClosureParam(Closure $closure) : void
|
||||
{
|
||||
$param = $closure->params[0];
|
||||
if (!$param->type instanceof Name) {
|
||||
return;
|
||||
}
|
||||
// update closure params
|
||||
if (!$this->nodeNameResolver->isName($param->type, self::RECTOR_CONFIG_CLASS)) {
|
||||
$param->type = new FullyQualified(self::RECTOR_CONFIG_CLASS);
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($param->var, self::RECTOR_CONFIG_VARIABLE)) {
|
||||
$param->var = new Variable(self::RECTOR_CONFIG_VARIABLE);
|
||||
}
|
||||
}
|
||||
public function isConfigClosure(Closure $closure) : bool
|
||||
{
|
||||
$params = $closure->getParams();
|
||||
if (\count($params) !== 1) {
|
||||
return \false;
|
||||
}
|
||||
$onlyParam = $params[0];
|
||||
$paramType = $onlyParam->type;
|
||||
if (!$paramType instanceof Name) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isNames($paramType, [self::CONTAINER_CONFIGURATOR_CLASS, self::RECTOR_CONFIG_CLASS]);
|
||||
}
|
||||
private function isFoundFluentServiceCall(Node $node) : bool
|
||||
{
|
||||
if (!$node instanceof MethodCall) {
|
||||
return \false;
|
||||
}
|
||||
$chains = $this->fluentChainMethodCallNodeAnalyzer->collectMethodCallNamesInChain($node);
|
||||
return \count($chains) > 1;
|
||||
}
|
||||
/**
|
||||
* @param Arg[] $args
|
||||
*/
|
||||
private function isNonFalseOption(array $args, string $optionName) : bool
|
||||
{
|
||||
if (!$this->valueResolver->isValue($args[0]->value, $optionName)) {
|
||||
return \false;
|
||||
}
|
||||
return !$this->valueResolver->isFalse($args[1]->value);
|
||||
}
|
||||
private function refactorConfigureRuleMethodCall(MethodCall $methodCall) : ?\PhpParser\Node\Expr\MethodCall
|
||||
{
|
||||
$caller = $methodCall->var;
|
||||
if (!$caller instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->containerConfiguratorCallAnalyzer->isMethodCallWithServicesSetRectorRule($caller)) {
|
||||
return null;
|
||||
}
|
||||
$methodCall->var = new Variable(self::RECTOR_CONFIG_VARIABLE);
|
||||
$methodCall->name = new Identifier('ruleWithConfiguration');
|
||||
$methodCall->args = \array_merge($caller->getArgs(), $methodCall->getArgs());
|
||||
return $methodCall;
|
||||
}
|
||||
private function refactorParameterName(MethodCall $methodCall) : ?MethodCall
|
||||
{
|
||||
$args = $methodCall->getArgs();
|
||||
foreach (self::PARAMETER_NAME_TO_METHOD_CALL_MAP as $parameterName => $methodName) {
|
||||
if (!$this->isNonFalseOption($args, $parameterName)) {
|
||||
continue;
|
||||
}
|
||||
$args = $this->valueResolver->isTrueOrFalse($args[1]->value) ? [] : [$args[1]];
|
||||
return new MethodCall(new Variable(self::RECTOR_CONFIG_VARIABLE), $methodName, $args);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'bb59a7c99ad30770689fe011c89377402bf6c7ba';
|
||||
public const PACKAGE_VERSION = '74f6b181e82f191c1e471d446a029a06dff16619';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-08-29 22:44:20';
|
||||
public const RELEASE_DATE = '2022-08-29 23:41:18';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitc882d4358abcd96633d7efdc3bcb1930::getLoader();
|
||||
return ComposerAutoloaderInit6fbd778a432c95223d21b3e7c10c4d3b::getLoader();
|
||||
|
|
|
@ -1740,10 +1740,6 @@ return array(
|
|||
'Rector\\Doctrine\\ValueObject\\DefaultAnnotationArgValue' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/DefaultAnnotationArgValue.php',
|
||||
'Rector\\Doctrine\\ValueObject\\PropertyNameAndPhpDocInfo' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/PropertyNameAndPhpDocInfo.php',
|
||||
'Rector\\Doctrine\\ValueObject\\PropertyNamesAndPhpDocInfos' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/PropertyNamesAndPhpDocInfos.php',
|
||||
'Rector\\DogFood\\NodeAnalyzer\\ContainerConfiguratorCallAnalyzer' => $baseDir . '/rules/DogFood/NodeAnalyzer/ContainerConfiguratorCallAnalyzer.php',
|
||||
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorEmptyAssignRemover' => $baseDir . '/rules/DogFood/NodeManipulator/ContainerConfiguratorEmptyAssignRemover.php',
|
||||
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorImportsMerger' => $baseDir . '/rules/DogFood/NodeManipulator/ContainerConfiguratorImportsMerger.php',
|
||||
'Rector\\DogFood\\Rector\\Closure\\UpgradeRectorConfigRector' => $baseDir . '/rules/DogFood/Rector/Closure/UpgradeRectorConfigRector.php',
|
||||
'Rector\\DowngradePhp53\\Rector\\Dir\\DirConstToFileConstRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp53/Rector/Dir/DirConstToFileConstRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Array_\\ShortArrayToLongArrayRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Array_/ShortArrayToLongArrayRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeStaticClosureRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Closure/DowngradeStaticClosureRector.php',
|
||||
|
@ -1924,7 +1920,6 @@ return array(
|
|||
'Rector\\Laravel\\Rector\\MethodCall\\LumenRoutesStringMiddlewareToArrayRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php',
|
||||
'Rector\\Laravel\\Rector\\MethodCall\\RedirectBackToBackHelperRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/RedirectBackToBackHelperRector.php',
|
||||
'Rector\\Laravel\\Rector\\MethodCall\\RedirectRouteToToRouteHelperRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php',
|
||||
'Rector\\Laravel\\Rector\\MethodCall\\RemoveAllOnDispatchingMethodsWithJobChainingRector' => $vendorDir . '/rector/rector-laravel/src/Rector/MethodCall/RemoveAllOnDispatchingMethodsWithJobChainingRector.php',
|
||||
'Rector\\Laravel\\Rector\\Namespace_\\FactoryDefinitionRector' => $vendorDir . '/rector/rector-laravel/src/Rector/Namespace_/FactoryDefinitionRector.php',
|
||||
'Rector\\Laravel\\Rector\\New_\\AddGuardToLoginEventRector' => $vendorDir . '/rector/rector-laravel/src/Rector/New_/AddGuardToLoginEventRector.php',
|
||||
'Rector\\Laravel\\Rector\\PropertyFetch\\OptionalToNullsafeOperatorRector' => $vendorDir . '/rector/rector-laravel/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php',
|
||||
|
@ -2420,15 +2415,7 @@ return array(
|
|||
'Rector\\PhpDocParser\\PhpParser\\SmartPhpParser' => $baseDir . '/packages/PhpDocParser/PhpParser/SmartPhpParser.php',
|
||||
'Rector\\PhpDocParser\\PhpParser\\SmartPhpParserFactory' => $baseDir . '/packages/PhpDocParser/PhpParser/SmartPhpParserFactory.php',
|
||||
'Rector\\PhpDocParser\\TypeAnalyzer\\ClassMethodReturnTypeResolver' => $baseDir . '/packages/PhpDocParser/TypeAnalyzer/ClassMethodReturnTypeResolver.php',
|
||||
'Rector\\PhpDocParser\\TypeAwareNodeFinder' => $baseDir . '/packages/PhpDocParser/TypeAwareNodeFinder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\AttributeKey' => $baseDir . '/packages/PhpDocParser/ValueObject/AttributeKey.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\ClassBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/ClassBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\MethodBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/MethodBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\NamespaceBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/NamespaceBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\ParamBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/ParamBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\PropertyBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/PropertyBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\TraitUseBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/TraitUseBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\UseBuilder' => $baseDir . '/packages/PhpDocParser/ValueObject/NodeBuilder/UseBuilder.php',
|
||||
'Rector\\PostRector\\Application\\PostFileProcessor' => $baseDir . '/packages/PostRector/Application/PostFileProcessor.php',
|
||||
'Rector\\PostRector\\Collector\\NodesToAddCollector' => $baseDir . '/packages/PostRector/Collector/NodesToAddCollector.php',
|
||||
'Rector\\PostRector\\Collector\\NodesToRemoveCollector' => $baseDir . '/packages/PostRector/Collector/NodesToRemoveCollector.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitc882d4358abcd96633d7efdc3bcb1930
|
||||
class ComposerAutoloaderInit6fbd778a432c95223d21b3e7c10c4d3b
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInitc882d4358abcd96633d7efdc3bcb1930
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitc882d4358abcd96633d7efdc3bcb1930', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6fbd778a432c95223d21b3e7c10c4d3b', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitc882d4358abcd96633d7efdc3bcb1930', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6fbd778a432c95223d21b3e7c10c4d3b', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6fbd778a432c95223d21b3e7c10c4d3b::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit6fbd778a432c95223d21b3e7c10c4d3b::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequirec882d4358abcd96633d7efdc3bcb1930($fileIdentifier, $file);
|
||||
composerRequire6fbd778a432c95223d21b3e7c10c4d3b($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInitc882d4358abcd96633d7efdc3bcb1930
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequirec882d4358abcd96633d7efdc3bcb1930($fileIdentifier, $file)
|
||||
function composerRequire6fbd778a432c95223d21b3e7c10c4d3b($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930
|
||||
class ComposerStaticInit6fbd778a432c95223d21b3e7c10c4d3b
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -2025,10 +2025,6 @@ class ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930
|
|||
'Rector\\Doctrine\\ValueObject\\DefaultAnnotationArgValue' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/DefaultAnnotationArgValue.php',
|
||||
'Rector\\Doctrine\\ValueObject\\PropertyNameAndPhpDocInfo' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/PropertyNameAndPhpDocInfo.php',
|
||||
'Rector\\Doctrine\\ValueObject\\PropertyNamesAndPhpDocInfos' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/PropertyNamesAndPhpDocInfos.php',
|
||||
'Rector\\DogFood\\NodeAnalyzer\\ContainerConfiguratorCallAnalyzer' => __DIR__ . '/../..' . '/rules/DogFood/NodeAnalyzer/ContainerConfiguratorCallAnalyzer.php',
|
||||
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorEmptyAssignRemover' => __DIR__ . '/../..' . '/rules/DogFood/NodeManipulator/ContainerConfiguratorEmptyAssignRemover.php',
|
||||
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorImportsMerger' => __DIR__ . '/../..' . '/rules/DogFood/NodeManipulator/ContainerConfiguratorImportsMerger.php',
|
||||
'Rector\\DogFood\\Rector\\Closure\\UpgradeRectorConfigRector' => __DIR__ . '/../..' . '/rules/DogFood/Rector/Closure/UpgradeRectorConfigRector.php',
|
||||
'Rector\\DowngradePhp53\\Rector\\Dir\\DirConstToFileConstRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp53/Rector/Dir/DirConstToFileConstRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Array_\\ShortArrayToLongArrayRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Array_/ShortArrayToLongArrayRector.php',
|
||||
'Rector\\DowngradePhp54\\Rector\\Closure\\DowngradeStaticClosureRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp54/Rector/Closure/DowngradeStaticClosureRector.php',
|
||||
|
@ -2209,7 +2205,6 @@ class ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930
|
|||
'Rector\\Laravel\\Rector\\MethodCall\\LumenRoutesStringMiddlewareToArrayRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php',
|
||||
'Rector\\Laravel\\Rector\\MethodCall\\RedirectBackToBackHelperRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/RedirectBackToBackHelperRector.php',
|
||||
'Rector\\Laravel\\Rector\\MethodCall\\RedirectRouteToToRouteHelperRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php',
|
||||
'Rector\\Laravel\\Rector\\MethodCall\\RemoveAllOnDispatchingMethodsWithJobChainingRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/MethodCall/RemoveAllOnDispatchingMethodsWithJobChainingRector.php',
|
||||
'Rector\\Laravel\\Rector\\Namespace_\\FactoryDefinitionRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/Namespace_/FactoryDefinitionRector.php',
|
||||
'Rector\\Laravel\\Rector\\New_\\AddGuardToLoginEventRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/New_/AddGuardToLoginEventRector.php',
|
||||
'Rector\\Laravel\\Rector\\PropertyFetch\\OptionalToNullsafeOperatorRector' => __DIR__ . '/..' . '/rector/rector-laravel/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php',
|
||||
|
@ -2705,15 +2700,7 @@ class ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930
|
|||
'Rector\\PhpDocParser\\PhpParser\\SmartPhpParser' => __DIR__ . '/../..' . '/packages/PhpDocParser/PhpParser/SmartPhpParser.php',
|
||||
'Rector\\PhpDocParser\\PhpParser\\SmartPhpParserFactory' => __DIR__ . '/../..' . '/packages/PhpDocParser/PhpParser/SmartPhpParserFactory.php',
|
||||
'Rector\\PhpDocParser\\TypeAnalyzer\\ClassMethodReturnTypeResolver' => __DIR__ . '/../..' . '/packages/PhpDocParser/TypeAnalyzer/ClassMethodReturnTypeResolver.php',
|
||||
'Rector\\PhpDocParser\\TypeAwareNodeFinder' => __DIR__ . '/../..' . '/packages/PhpDocParser/TypeAwareNodeFinder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\AttributeKey' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/AttributeKey.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\ClassBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/ClassBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\MethodBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/MethodBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\NamespaceBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/NamespaceBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\ParamBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/ParamBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\PropertyBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/PropertyBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\TraitUseBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/TraitUseBuilder.php',
|
||||
'Rector\\PhpDocParser\\ValueObject\\NodeBuilder\\UseBuilder' => __DIR__ . '/../..' . '/packages/PhpDocParser/ValueObject/NodeBuilder/UseBuilder.php',
|
||||
'Rector\\PostRector\\Application\\PostFileProcessor' => __DIR__ . '/../..' . '/packages/PostRector/Application/PostFileProcessor.php',
|
||||
'Rector\\PostRector\\Collector\\NodesToAddCollector' => __DIR__ . '/../..' . '/packages/PostRector/Collector/NodesToAddCollector.php',
|
||||
'Rector\\PostRector\\Collector\\NodesToRemoveCollector' => __DIR__ . '/../..' . '/packages/PostRector/Collector/NodesToRemoveCollector.php',
|
||||
|
@ -3205,9 +3192,9 @@ class ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitc882d4358abcd96633d7efdc3bcb1930::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6fbd778a432c95223d21b3e7c10c4d3b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6fbd778a432c95223d21b3e7c10c4d3b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6fbd778a432c95223d21b3e7c10c4d3b::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -1853,12 +1853,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "644498fcf6e9904a39f48874252361f40a75d63c"
|
||||
"reference": "ccb870f41d2177572841b4a3779bf72eb6ec73a1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/644498fcf6e9904a39f48874252361f40a75d63c",
|
||||
"reference": "644498fcf6e9904a39f48874252361f40a75d63c",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/ccb870f41d2177572841b4a3779bf72eb6ec73a1",
|
||||
"reference": "ccb870f41d2177572841b4a3779bf72eb6ec73a1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1875,6 +1875,7 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.0",
|
||||
"phpunit\/phpunit": "^9.5",
|
||||
"rector\/phpstan-rules": "^0.5.15",
|
||||
"rector\/rector-generator": "^0.6.10",
|
||||
"rector\/rector-src": "dev-main",
|
||||
"symplify\/easy-coding-standard": "^11.0",
|
||||
"symplify\/monorepo-builder": "^11.1",
|
||||
|
@ -1883,7 +1884,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-08-29T20:16:53+00:00",
|
||||
"time": "2022-08-29T20:58:40+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
@ -1991,12 +1992,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-laravel.git",
|
||||
"reference": "30f93ff57c00a7726d3e4a7e3d135ed47852db56"
|
||||
"reference": "815de8ff73570a4b22712c65fbaa8fa8c72eb523"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-laravel\/zipball\/30f93ff57c00a7726d3e4a7e3d135ed47852db56",
|
||||
"reference": "30f93ff57c00a7726d3e4a7e3d135ed47852db56",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-laravel\/zipball\/815de8ff73570a4b22712c65fbaa8fa8c72eb523",
|
||||
"reference": "815de8ff73570a4b22712c65fbaa8fa8c72eb523",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2020,7 +2021,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.0",
|
||||
"symplify\/vendor-patches": "^11.0"
|
||||
},
|
||||
"time": "2022-08-29T20:15:47+00:00",
|
||||
"time": "2022-08-29T20:57:15+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
@ -2125,12 +2126,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
|
||||
"reference": "caef0bf0bd278878069d88193d3db4ff0c5eea55"
|
||||
"reference": "197905062a1d5ad10cf3ee9d3019a472b940dc96"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/caef0bf0bd278878069d88193d3db4ff0c5eea55",
|
||||
"reference": "caef0bf0bd278878069d88193d3db4ff0c5eea55",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/197905062a1d5ad10cf3ee9d3019a472b940dc96",
|
||||
"reference": "197905062a1d5ad10cf3ee9d3019a472b940dc96",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2146,6 +2147,7 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.1",
|
||||
"phpunit\/phpunit": "^9.5",
|
||||
"rector\/phpstan-rules": "^0.5.15",
|
||||
"rector\/rector-generator": "^0.6.10",
|
||||
"rector\/rector-src": "dev-main",
|
||||
"symplify\/easy-ci": "^11.0",
|
||||
"symplify\/easy-coding-standard": "^11.0",
|
||||
|
@ -2155,7 +2157,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.0",
|
||||
"symplify\/vendor-patches": "^11.0"
|
||||
},
|
||||
"time": "2022-08-29T20:18:09+00:00",
|
||||
"time": "2022-08-29T20:58:05+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
@ -2193,12 +2195,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
|
||||
"reference": "07ac609f3347aeefb6495d90277de550a4fd7639"
|
||||
"reference": "71a68282e8b6ba6b677dfee1f0da07bdc66465b9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/07ac609f3347aeefb6495d90277de550a4fd7639",
|
||||
"reference": "07ac609f3347aeefb6495d90277de550a4fd7639",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/71a68282e8b6ba6b677dfee1f0da07bdc66465b9",
|
||||
"reference": "71a68282e8b6ba6b677dfee1f0da07bdc66465b9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2216,6 +2218,7 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.2",
|
||||
"phpunit\/phpunit": "^9.5",
|
||||
"rector\/phpstan-rules": "^0.5.16",
|
||||
"rector\/rector-generator": "^0.6.10",
|
||||
"rector\/rector-src": "dev-main",
|
||||
"symfony\/routing": "^6.1",
|
||||
"symfony\/security-core": "^6.1",
|
||||
|
@ -2227,7 +2230,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-08-29T20:19:30+00:00",
|
||||
"time": "2022-08-29T20:59:33+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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 644498f'), '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 60db04f'), '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 30f93ff'), '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 caef0bf'), '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 07ac609'));
|
||||
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 ccb870f'), '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 60db04f'), '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 815de8f'), '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 1979050'), '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 71a6828'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
"symplify\/monorepo-builder": "^11.1",
|
||||
"phpstan\/phpstan-webmozart-assert": "^1.0",
|
||||
"phpstan\/phpstan-strict-rules": "^1.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
"symplify\/vendor-patches": "^11.1",
|
||||
"rector\/rector-generator": "^0.6.10"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeFactory;
|
||||
|
||||
use PhpParser\Builder\Method;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
|
@ -14,7 +15,6 @@ use PhpParser\Node\Stmt\Property;
|
|||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PhpDocParser\ValueObject\NodeBuilder\MethodBuilder;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
final class ConstructClassMethodFactory
|
||||
|
@ -54,11 +54,11 @@ final class ConstructClassMethodFactory
|
|||
$params[] = $this->createParam($publicProperty, $propertyName);
|
||||
$assigns[] = $this->createAssign($propertyName);
|
||||
}
|
||||
$methodBuilder = new MethodBuilder(MethodName::CONSTRUCT);
|
||||
$methodBuilder->makePublic();
|
||||
$methodBuilder->addParams($params);
|
||||
$methodBuilder->addStmts($assigns);
|
||||
return $methodBuilder->getNode();
|
||||
$method = new Method(MethodName::CONSTRUCT);
|
||||
$method->makePublic();
|
||||
$method->addParams($params);
|
||||
$method->addStmts($assigns);
|
||||
return $method->getNode();
|
||||
}
|
||||
/**
|
||||
* @return Property[]
|
||||
|
|
|
@ -10,7 +10,6 @@ use Rector\Arguments\ValueObject\ArgumentAdder;
|
|||
use Rector\Config\RectorConfig;
|
||||
use Rector\Laravel\Rector\ClassMethod\AddArgumentDefaultValueRector;
|
||||
use Rector\Laravel\Rector\ClassMethod\AddParentRegisterToEventServiceProviderRector;
|
||||
use Rector\Laravel\Rector\MethodCall\RemoveAllOnDispatchingMethodsWithJobChainingRector;
|
||||
use Rector\Laravel\ValueObject\AddArgumentDefaultValue;
|
||||
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
|
||||
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
|
||||
|
@ -52,6 +51,4 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
# https://github.com/laravel/framework/commit/fd662d4699776a94e7ead2a42e82c340363fc5a6
|
||||
new MethodCallRename('Illuminate\\Testing\\TestResponse', 'assertExactJson', 'assertSimilarJson'),
|
||||
]);
|
||||
# https://github.com/laravel/framework/commit/de662daf75207a8dd69565ed3630def74bc538d3
|
||||
$rectorConfig->rule(RemoveAllOnDispatchingMethodsWithJobChainingRector::class);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 26 Rules Overview
|
||||
# 25 Rules Overview
|
||||
|
||||
## AddArgumentDefaultValueRector
|
||||
|
||||
|
@ -468,26 +468,6 @@ Replace `redirect()->route("home")` and `Redirect::route("home")` with `to_route
|
|||
|
||||
<br>
|
||||
|
||||
## RemoveAllOnDispatchingMethodsWithJobChainingRector
|
||||
|
||||
Remove `allOnQueue()` and `allOnConnection()` methods used with job chaining, use the `onQueue()` and `onConnection()` methods instead.
|
||||
|
||||
- class: [`Rector\Laravel\Rector\MethodCall\RemoveAllOnDispatchingMethodsWithJobChainingRector`](../src/Rector/MethodCall/RemoveAllOnDispatchingMethodsWithJobChainingRector.php)
|
||||
|
||||
```diff
|
||||
Job::withChain([
|
||||
new ChainJob(),
|
||||
])
|
||||
- ->dispatch()
|
||||
- ->allOnConnection('redis')
|
||||
- ->allOnQueue('podcasts');
|
||||
+ ->onQueue('podcasts')
|
||||
+ ->onConnection('redis')
|
||||
+ ->dispatch();
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## RemoveDumpDataDeadCodeRector
|
||||
|
||||
It will removes the dump data just like dd or dump functions from the code.`
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Laravel\NodeFactory;
|
||||
|
||||
use PhpParser\Builder\Method;
|
||||
use PhpParser\Builder\Property;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
|
@ -21,8 +23,6 @@ use Rector\Core\PhpParser\Node\NodeFactory;
|
|||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Rector\PhpDocParser\ValueObject\NodeBuilder\MethodBuilder;
|
||||
use Rector\PhpDocParser\ValueObject\NodeBuilder\PropertyBuilder;
|
||||
final class ModelFactoryNodeFactory
|
||||
{
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ final class ModelFactoryNodeFactory
|
|||
{
|
||||
$class = new Class_($name . 'Factory');
|
||||
$class->extends = new FullyQualified('Illuminate\\Database\\Eloquent\\Factories\\Factory');
|
||||
$propertyBuilder = new PropertyBuilder('model');
|
||||
$propertyBuilder = new Property('model');
|
||||
$propertyBuilder->makeProtected();
|
||||
$propertyBuilder->setDefault($expr);
|
||||
$property = $propertyBuilder->getNode();
|
||||
|
@ -155,9 +155,9 @@ final class ModelFactoryNodeFactory
|
|||
*/
|
||||
private function createPublicMethod(string $name, array $stmts) : ClassMethod
|
||||
{
|
||||
$methodBuilder = new MethodBuilder($name);
|
||||
$methodBuilder->makePublic();
|
||||
$methodBuilder->addStmts($stmts);
|
||||
return $methodBuilder->getNode();
|
||||
$method = new Method($name);
|
||||
$method->makePublic();
|
||||
$method->addStmts($stmts);
|
||||
return $method->getNode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ use PhpParser\Node\Stmt\Property;
|
|||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\NodeManipulator\ClassInsertManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\PhpDocParser\ValueObject\NodeBuilder\PropertyBuilder;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202208\Webmozart\Assert\Assert;
|
||||
|
@ -110,7 +109,7 @@ CODE_SAMPLE
|
|||
}
|
||||
private function createCastsProperty() : Property
|
||||
{
|
||||
$propertyBuilder = new PropertyBuilder('casts');
|
||||
$propertyBuilder = new \PhpParser\Builder\Property('casts');
|
||||
$propertyBuilder->makeProtected();
|
||||
$propertyBuilder->setDefault([]);
|
||||
$property = $propertyBuilder->getNode();
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Laravel\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Laravel\Tests\Rector\MethodCall\RemoveAllOnDispatchingMethodsWithJobChainingRector\RemoveAllOnDispatchingMethodsWithJobChainingRectorTest
|
||||
*/
|
||||
final class RemoveAllOnDispatchingMethodsWithJobChainingRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const DISPATCH = 'dispatch';
|
||||
/**
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const SWAPPED_METHODS = ['allOnQueue' => 'onQueue', 'allOnConnection' => 'onConnection'];
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer
|
||||
*/
|
||||
private $fluentChainMethodCallNodeAnalyzer;
|
||||
public function __construct(FluentChainMethodCallNodeAnalyzer $fluentChainMethodCallNodeAnalyzer)
|
||||
{
|
||||
$this->fluentChainMethodCallNodeAnalyzer = $fluentChainMethodCallNodeAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Remove allOnQueue() and allOnConnection() methods used with job chaining, use the onQueue() and onConnection() methods instead.', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
Job::withChain([
|
||||
new ChainJob(),
|
||||
])
|
||||
->dispatch()
|
||||
->allOnConnection('redis')
|
||||
->allOnQueue('podcasts');
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
Job::withChain([
|
||||
new ChainJob(),
|
||||
])
|
||||
->onQueue('podcasts')
|
||||
->onConnection('redis')
|
||||
->dispatch();
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if (!$this->isNames($node->name, \array_keys(self::SWAPPED_METHODS))) {
|
||||
return null;
|
||||
}
|
||||
$rootExpr = $this->fluentChainMethodCallNodeAnalyzer->resolveRootExpr($node);
|
||||
if (!$this->isObjectType($rootExpr, new ObjectType('Illuminate\\Foundation\\Bus\\Dispatchable'))) {
|
||||
return null;
|
||||
}
|
||||
// Note that this change only affects code using the withChain method.
|
||||
$callerNode = $rootExpr->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$callerNode instanceof StaticCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($callerNode->name, 'withChain')) {
|
||||
return null;
|
||||
}
|
||||
$names = $this->fluentChainMethodCallNodeAnalyzer->collectMethodCallNamesInChain($node);
|
||||
if (!\in_array(self::DISPATCH, $names, \true)) {
|
||||
return null;
|
||||
}
|
||||
// These methods should be called before calling the dispatch method.
|
||||
$end = $node->var;
|
||||
$current = $node->var;
|
||||
while ($current instanceof MethodCall) {
|
||||
if ($this->isName($current->name, self::DISPATCH)) {
|
||||
$var = $current->var;
|
||||
$current->var = $node;
|
||||
$node->name = new Identifier(self::SWAPPED_METHODS[$this->getName($node->name)]);
|
||||
$node->var = $var;
|
||||
break;
|
||||
}
|
||||
$current = $current->var;
|
||||
}
|
||||
return $end;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,8 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.1",
|
||||
"symplify\/vendor-patches": "^11.0",
|
||||
"symplify\/monorepo-builder": "^11.0",
|
||||
"symplify\/easy-ci": "^11.0"
|
||||
"symplify\/easy-ci": "^11.0",
|
||||
"rector\/rector-generator": "^0.6.10"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\PHPUnit\NodeFactory;
|
||||
|
||||
use PhpParser\Builder\Method;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\ArrayItem;
|
||||
use PhpParser\Node\Expr\Yield_;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use Rector\PhpDocParser\ValueObject\NodeBuilder\MethodBuilder;
|
||||
use Rector\PHPUnit\ValueObject\DataProviderClassMethodRecipe;
|
||||
final class DataProviderClassMethodFactory
|
||||
{
|
||||
public function createFromRecipe(DataProviderClassMethodRecipe $dataProviderClassMethodRecipe) : ClassMethod
|
||||
{
|
||||
$methodBuilder = new MethodBuilder($dataProviderClassMethodRecipe->getMethodName());
|
||||
$methodBuilder->makePublic();
|
||||
$classMethod = $methodBuilder->getNode();
|
||||
$method = new Method($dataProviderClassMethodRecipe->getMethodName());
|
||||
$method->makePublic();
|
||||
$classMethod = $method->getNode();
|
||||
foreach ($dataProviderClassMethodRecipe->getArgs() as $arg) {
|
||||
$value = $arg->value;
|
||||
if (!$value instanceof Array_) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.2",
|
||||
"phpunit\/phpunit": "^9.5",
|
||||
"rector\/phpstan-rules": "^0.5.16",
|
||||
"rector\/rector-generator": "^0.6.10",
|
||||
"rector\/rector-src": "dev-main",
|
||||
"symfony\/routing": "^6.1",
|
||||
"symfony\/security-core": "^6.1",
|
||||
|
|
|
@ -20,7 +20,6 @@ use PHPStan\Type\StringType;
|
|||
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\PhpDocParser\ValueObject\NodeBuilder\PropertyBuilder;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
|
@ -203,10 +202,10 @@ CODE_SAMPLE
|
|||
}
|
||||
private function createStaticProtectedPropertyWithDefault(string $name, Node $node) : Property
|
||||
{
|
||||
$propertyBuilder = new PropertyBuilder($name);
|
||||
$propertyBuilder->makeProtected();
|
||||
$propertyBuilder->makeStatic();
|
||||
$propertyBuilder->setDefault($node);
|
||||
return $propertyBuilder->getNode();
|
||||
$property = new \PhpParser\Builder\Property($name);
|
||||
$property->makeProtected();
|
||||
$property->makeStatic();
|
||||
$property->setDefault($node);
|
||||
return $property->getNode();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue