mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit cd48bfcc4785fb0d2cf828240f8f71231b232c85
cd48bfcc47
Cleanup removeNodeFromStatements(), removeArg(), removeParam(), removeStmt() methods and remove nodes directly (#4012)
This commit is contained in:
parent
b6aa01ccb7
commit
c98c306aa8
|
@ -4,16 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\NodeRemoval;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\ChangesReporting\Collector\RectorChangeCollector;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PostRector\Collector\NodesToRemoveCollector;
|
||||
final class NodeRemover
|
||||
|
@ -47,21 +38,6 @@ final class NodeRemover
|
|||
$this->nodesToRemoveCollector->addNodeToRemove($node);
|
||||
$this->rectorChangeCollector->notifyNodeFileInfo($node);
|
||||
}
|
||||
/**
|
||||
* @api used in rector-doctrine
|
||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $nodeWithStatements
|
||||
*/
|
||||
public function removeNodeFromStatements($nodeWithStatements, Node $toBeRemovedNode) : void
|
||||
{
|
||||
foreach ((array) $nodeWithStatements->stmts as $key => $stmt) {
|
||||
if ($toBeRemovedNode !== $stmt) {
|
||||
continue;
|
||||
}
|
||||
$this->removeNode($stmt);
|
||||
unset($nodeWithStatements->stmts[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
*/
|
||||
|
@ -71,51 +47,4 @@ final class NodeRemover
|
|||
$this->removeNode($node);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param int|\PhpParser\Node\Param $keyOrParam
|
||||
*/
|
||||
public function removeParam(ClassMethod $classMethod, $keyOrParam) : void
|
||||
{
|
||||
$key = $keyOrParam instanceof Param ? $keyOrParam->getAttribute(AttributeKey::PARAMETER_POSITION) : $keyOrParam;
|
||||
if ($classMethod->params === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
// already removed
|
||||
if (!isset($classMethod->params[$key])) {
|
||||
return;
|
||||
}
|
||||
$this->removeNode($classMethod->params[$key]);
|
||||
unset($classMethod->params[$key]);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
|
||||
*/
|
||||
public function removeArg($node, int $key) : void
|
||||
{
|
||||
if ($node->getArgs() === []) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
// already removed
|
||||
if (!isset($node->args[$key])) {
|
||||
return;
|
||||
}
|
||||
$this->removeNode($node->args[$key]);
|
||||
unset($node->args[$key]);
|
||||
}
|
||||
/**
|
||||
* @api phpunit
|
||||
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
public function removeStmt($functionLike, int $key) : void
|
||||
{
|
||||
if ($functionLike->stmts === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
// already removed
|
||||
if (!isset($functionLike->stmts[$key])) {
|
||||
return;
|
||||
}
|
||||
$this->removeNode($functionLike->stmts[$key]);
|
||||
unset($functionLike->stmts[$key]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ CODE_SAMPLE
|
|||
$paramName = $this->getName($paramNode->var);
|
||||
$propertyMetadata = new PropertyMetadata($paramName, $paramType, Class_::MODIFIER_PRIVATE);
|
||||
$this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
|
||||
$this->nodeRemover->removeParam($classMethod, $key);
|
||||
unset($classMethod->params[$key]);
|
||||
$this->variablesToPropertyFetchCollection->addVariableNameAndType($paramName, $paramType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,9 +83,9 @@ CODE_SAMPLE
|
|||
{
|
||||
if ($argumentRemover->getValue() === null) {
|
||||
if ($node instanceof MethodCall || $node instanceof StaticCall) {
|
||||
$this->nodeRemover->removeArg($node, $argumentRemover->getPosition());
|
||||
unset($node->args[$argumentRemover->getPosition()]);
|
||||
} else {
|
||||
$this->nodeRemover->removeParam($node, $argumentRemover->getPosition());
|
||||
unset($node->params[$argumentRemover->getPosition()]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ CODE_SAMPLE
|
|||
}
|
||||
if ($this->isArgumentValueMatch($node->args[$argumentRemover->getPosition()], $match)) {
|
||||
$this->hasChanged = \true;
|
||||
$this->nodeRemover->removeArg($node, $argumentRemover->getPosition());
|
||||
unset($node->args[$argumentRemover->getPosition()]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -113,14 +113,14 @@ CODE_SAMPLE
|
|||
{
|
||||
if ($node instanceof MethodCall || $node instanceof StaticCall) {
|
||||
if (isset($node->args[$position]) && $this->isName($node->args[$position], $name)) {
|
||||
$this->nodeRemover->removeArg($node, $position);
|
||||
unset($node->args[$position]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(isset($node->params[$position]) && $this->isName($node->params[$position], $name))) {
|
||||
return;
|
||||
}
|
||||
$this->nodeRemover->removeParam($node, $position);
|
||||
unset($node->params[$position]);
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $values
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8f24c73f1894356dd9ad3745924d027fa65a5602';
|
||||
public const PACKAGE_VERSION = 'cd48bfcc4785fb0d2cf828240f8f71231b232c85';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-29 09:05:07';
|
||||
public const RELEASE_DATE = '2023-05-29 08:35:20';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit7977ba338c257f0b70710b3404e69e00::getLoader();
|
||||
return ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155::getLoader();
|
||||
|
|
|
@ -1643,7 +1643,6 @@ return array(
|
|||
'Rector\\Doctrine\\NodeAnalyzer\\AttrinationFinder' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AttrinationFinder.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\ConstructorAssignPropertyAnalyzer' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/ConstructorAssignPropertyAnalyzer.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\EntityObjectTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/EntityObjectTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\MethodCallNameOnTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/MethodCallNameOnTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\SetterClassMethodAnalyzer' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/SetterClassMethodAnalyzer.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\TargetEntityResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/TargetEntityResolver.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\ArrayCollectionAssignFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/ArrayCollectionAssignFactory.php',
|
||||
|
@ -1656,7 +1655,6 @@ return array(
|
|||
'Rector\\Doctrine\\NodeFactory\\ValueAssignFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/ValueAssignFactory.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\ColumnPropertyTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/ColumnPropertyTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\ConstructorManipulator' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/ConstructorManipulator.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\DependencyRemover' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/DependencyRemover.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\DoctrineItemDefaultValueManipulator' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/DoctrineItemDefaultValueManipulator.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\IssetDimFetchCleaner' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/IssetDimFetchCleaner.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\NullabilityColumnPropertyTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/NullabilityColumnPropertyTypeResolver.php',
|
||||
|
@ -1671,7 +1669,6 @@ return array(
|
|||
'Rector\\Doctrine\\Rector\\Class_\\AddEntityIdByConditionRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/AddEntityIdByConditionRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\ClassAnnotationToNamedArgumentConstructorRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/ClassAnnotationToNamedArgumentConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\InitializeDefaultEntityCollectionRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/InitializeDefaultEntityCollectionRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\ManagerRegistryGetManagerToEntityManagerRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\MoveCurrentDateTimeDefaultInEntityToConstructorRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\MoveRepositoryFromParentToConstructorRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/MoveRepositoryFromParentToConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\RemoveEmptyTableAttributeRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/RemoveEmptyTableAttributeRector.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit7977ba338c257f0b70710b3404e69e00
|
||||
class ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit7977ba338c257f0b70710b3404e69e00
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit7977ba338c257f0b70710b3404e69e00', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit7977ba338c257f0b70710b3404e69e00', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7977ba338c257f0b70710b3404e69e00::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitf1683014dc82e46c87167ac2cba04155::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit7977ba338c257f0b70710b3404e69e00::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit7977ba338c257f0b70710b3404e69e00
|
||||
class ComposerStaticInitf1683014dc82e46c87167ac2cba04155
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1885,7 +1885,6 @@ class ComposerStaticInit7977ba338c257f0b70710b3404e69e00
|
|||
'Rector\\Doctrine\\NodeAnalyzer\\AttrinationFinder' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AttrinationFinder.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\ConstructorAssignPropertyAnalyzer' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/ConstructorAssignPropertyAnalyzer.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\EntityObjectTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/EntityObjectTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\MethodCallNameOnTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/MethodCallNameOnTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\SetterClassMethodAnalyzer' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/SetterClassMethodAnalyzer.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\TargetEntityResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/TargetEntityResolver.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\ArrayCollectionAssignFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/ArrayCollectionAssignFactory.php',
|
||||
|
@ -1898,7 +1897,6 @@ class ComposerStaticInit7977ba338c257f0b70710b3404e69e00
|
|||
'Rector\\Doctrine\\NodeFactory\\ValueAssignFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/ValueAssignFactory.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\ColumnPropertyTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/ColumnPropertyTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\ConstructorManipulator' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/ConstructorManipulator.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\DependencyRemover' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/DependencyRemover.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\DoctrineItemDefaultValueManipulator' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/DoctrineItemDefaultValueManipulator.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\IssetDimFetchCleaner' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/IssetDimFetchCleaner.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\NullabilityColumnPropertyTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/NullabilityColumnPropertyTypeResolver.php',
|
||||
|
@ -1913,7 +1911,6 @@ class ComposerStaticInit7977ba338c257f0b70710b3404e69e00
|
|||
'Rector\\Doctrine\\Rector\\Class_\\AddEntityIdByConditionRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/AddEntityIdByConditionRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\ClassAnnotationToNamedArgumentConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/ClassAnnotationToNamedArgumentConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\InitializeDefaultEntityCollectionRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/InitializeDefaultEntityCollectionRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\ManagerRegistryGetManagerToEntityManagerRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\MoveCurrentDateTimeDefaultInEntityToConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\MoveRepositoryFromParentToConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/MoveRepositoryFromParentToConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\RemoveEmptyTableAttributeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/RemoveEmptyTableAttributeRector.php',
|
||||
|
@ -3086,9 +3083,9 @@ class ComposerStaticInit7977ba338c257f0b70710b3404e69e00
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7977ba338c257f0b70710b3404e69e00::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit7977ba338c257f0b70710b3404e69e00::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit7977ba338c257f0b70710b3404e69e00::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -1855,20 +1855,17 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "bc6805cc485416b82f0e6fb09f815f07e083f8ba"
|
||||
"reference": "cafabaf07ebd7a6ff5e69abe2c99b7ab277fdee6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/bc6805cc485416b82f0e6fb09f815f07e083f8ba",
|
||||
"reference": "bc6805cc485416b82f0e6fb09f815f07e083f8ba",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/cafabaf07ebd7a6ff5e69abe2c99b7ab277fdee6",
|
||||
"reference": "cafabaf07ebd7a6ff5e69abe2c99b7ab277fdee6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"conflict": {
|
||||
"rector\/rector": "<0.11"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine\/orm": "^2.10",
|
||||
"phpstan\/extension-installer": "^1.1",
|
||||
|
@ -1877,24 +1874,22 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.0",
|
||||
"phpunit\/phpunit": "^10.0",
|
||||
"rector\/phpstan-rules": "^0.6",
|
||||
"rector\/rector-debugging": "dev-main",
|
||||
"rector\/rector-generator": "^0.6.10",
|
||||
"rector\/rector-generator": "^0.6",
|
||||
"rector\/rector-src": "dev-main",
|
||||
"symplify\/easy-ci": "^11.2",
|
||||
"symplify\/easy-coding-standard": "^11.2",
|
||||
"symplify\/phpstan-extensions": "^11.1",
|
||||
"symplify\/phpstan-rules": "^11.1",
|
||||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
"symplify\/vendor-patches": "^11.1",
|
||||
"tomasvotruba\/type-coverage": "^0.2.0",
|
||||
"tomasvotruba\/unused-public": "^0.1.10"
|
||||
},
|
||||
"time": "2023-05-26T23:58:12+00:00",
|
||||
"time": "2023-05-29T08:18:21+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
"enable-patching": true,
|
||||
"branch-alias": {
|
||||
"dev-main": "0.11-dev"
|
||||
},
|
||||
"rector": {
|
||||
"includes": [
|
||||
"config\/config.php"
|
||||
|
@ -1992,12 +1987,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
|
||||
"reference": "659f0153a4de3c48fa6da7cc755679d74bb9f26d"
|
||||
"reference": "edbdd0e70f2a99e163e3c9b675ffb4c743bc8cb7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/659f0153a4de3c48fa6da7cc755679d74bb9f26d",
|
||||
"reference": "659f0153a4de3c48fa6da7cc755679d74bb9f26d",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/edbdd0e70f2a99e163e3c9b675ffb4c743bc8cb7",
|
||||
"reference": "edbdd0e70f2a99e163e3c9b675ffb4c743bc8cb7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2026,7 +2021,7 @@
|
|||
"tomasvotruba\/type-coverage": "^0.1",
|
||||
"tomasvotruba\/unused-public": "^0.1"
|
||||
},
|
||||
"time": "2023-05-28T14:09:34+00:00",
|
||||
"time": "2023-05-29T08:30:48+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-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 bc6805c'), '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 abf0a7f'), '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 659f015'), '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 3878c88'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main cafabaf'), '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 abf0a7f'), '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 edbdd0e'), '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 3878c88'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -20,9 +20,10 @@
|
|||
"phpstan\/phpstan-webmozart-assert": "^1.0",
|
||||
"phpstan\/phpstan-strict-rules": "^1.1",
|
||||
"symplify\/vendor-patches": "^11.1",
|
||||
"rector\/rector-generator": "^0.6.10",
|
||||
"rector\/rector-debugging": "dev-main",
|
||||
"symplify\/easy-ci": "^11.2"
|
||||
"rector\/rector-generator": "^0.6",
|
||||
"symplify\/easy-ci": "^11.2",
|
||||
"tomasvotruba\/unused-public": "^0.1.10",
|
||||
"tomasvotruba\/type-coverage": "^0.2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -47,23 +48,16 @@
|
|||
},
|
||||
"extra": {
|
||||
"enable-patching": true,
|
||||
"branch-alias": {
|
||||
"dev-main": "0.11-dev"
|
||||
},
|
||||
"rector": {
|
||||
"includes": [
|
||||
"config\/config.php"
|
||||
]
|
||||
}
|
||||
},
|
||||
"conflict": {
|
||||
"rector\/rector": "<0.11"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"composer\/package-versions-deprecated": false,
|
||||
"cweagans\/composer-patches": true,
|
||||
"rector\/extension-installer": true,
|
||||
"phpstan\/extension-installer": true
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace RectorPrefix202305;
|
|||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Doctrine\Rector\Class_\InitializeDefaultEntityCollectionRector;
|
||||
use Rector\Doctrine\Rector\Class_\ManagerRegistryGetManagerToEntityManagerRector;
|
||||
use Rector\Doctrine\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector;
|
||||
use Rector\Doctrine\Rector\Class_\RemoveEmptyTableAttributeRector;
|
||||
use Rector\Doctrine\Rector\Class_\RemoveRedundantDefaultClassAnnotationValuesRector;
|
||||
|
@ -22,21 +21,22 @@ use Rector\Doctrine\Rector\Property\TypedPropertyFromToOneRelationTypeRector;
|
|||
use Rector\Transform\Rector\Attribute\AttributeKeyToClassConstFetchRector;
|
||||
use Rector\Transform\ValueObject\AttributeKeyToClassConstFetch;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->rule(ManagerRegistryGetManagerToEntityManagerRector::class);
|
||||
$rectorConfig->rule(InitializeDefaultEntityCollectionRector::class);
|
||||
$rectorConfig->rule(MakeEntitySetterNullabilityInSyncWithPropertyRector::class);
|
||||
$rectorConfig->rule(MakeEntityDateTimePropertyDateTimeInterfaceRector::class);
|
||||
$rectorConfig->rule(MoveCurrentDateTimeDefaultInEntityToConstructorRector::class);
|
||||
$rectorConfig->rule(CorrectDefaultTypesOnEntityPropertyRector::class);
|
||||
$rectorConfig->rule(ChangeBigIntEntityPropertyToIntTypeRector::class);
|
||||
$rectorConfig->rule(ImproveDoctrineCollectionDocTypeInEntityRector::class);
|
||||
$rectorConfig->rule(RemoveRedundantDefaultPropertyAnnotationValuesRector::class);
|
||||
$rectorConfig->rule(RemoveRedundantDefaultClassAnnotationValuesRector::class);
|
||||
$rectorConfig->rule(RemoveEmptyTableAttributeRector::class);
|
||||
// typed properties in entities from annotations/attributes
|
||||
$rectorConfig->rule(TypedPropertyFromColumnTypeRector::class);
|
||||
$rectorConfig->rule(TypedPropertyFromToOneRelationTypeRector::class);
|
||||
$rectorConfig->rule(TypedPropertyFromToManyRelationTypeRector::class);
|
||||
$rectorConfig->rule(TypedPropertyFromDoctrineCollectionRector::class);
|
||||
$rectorConfig->rules([
|
||||
InitializeDefaultEntityCollectionRector::class,
|
||||
MakeEntitySetterNullabilityInSyncWithPropertyRector::class,
|
||||
MakeEntityDateTimePropertyDateTimeInterfaceRector::class,
|
||||
MoveCurrentDateTimeDefaultInEntityToConstructorRector::class,
|
||||
CorrectDefaultTypesOnEntityPropertyRector::class,
|
||||
ChangeBigIntEntityPropertyToIntTypeRector::class,
|
||||
ImproveDoctrineCollectionDocTypeInEntityRector::class,
|
||||
RemoveRedundantDefaultPropertyAnnotationValuesRector::class,
|
||||
RemoveRedundantDefaultClassAnnotationValuesRector::class,
|
||||
RemoveEmptyTableAttributeRector::class,
|
||||
// typed properties in entities from annotations/attributes
|
||||
TypedPropertyFromColumnTypeRector::class,
|
||||
TypedPropertyFromToOneRelationTypeRector::class,
|
||||
TypedPropertyFromToManyRelationTypeRector::class,
|
||||
TypedPropertyFromDoctrineCollectionRector::class,
|
||||
]);
|
||||
$rectorConfig->ruleWithConfiguration(AttributeKeyToClassConstFetchRector::class, [new AttributeKeyToClassConstFetch('Doctrine\\ORM\\Mapping\\Column', 'type', 'Doctrine\\DBAL\\Types\\Types', ['array' => 'ARRAY', 'ascii_string' => 'ASCII_STRING', 'bigint' => 'BIGINT', 'binary' => 'BINARY', 'blob' => 'BLOB', 'boolean' => 'BOOLEAN', 'date' => 'DATE_MUTABLE', 'date_immutable' => 'DATE_IMMUTABLE', 'dateinterval' => 'DATEINTERVAL', 'datetime' => 'DATETIME_MUTABLE', 'datetime_immutable' => 'DATETIME_IMMUTABLE', 'datetimetz' => 'DATETIMETZ_MUTABLE', 'datetimetz_immutable' => 'DATETIMETZ_IMMUTABLE', 'decimal' => 'DECIMAL', 'float' => 'FLOAT', 'guid' => 'GUID', 'integer' => 'INTEGER', 'json' => 'JSON', 'object' => 'OBJECT', 'simple_array' => 'SIMPLE_ARRAY', 'smallint' => 'SMALLINT', 'string' => 'STRING', 'text' => 'TEXT', 'time' => 'TIME_MUTABLE', 'time_immutable' => 'TIME_IMMUTABLE'])]);
|
||||
};
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
final class MethodCallNameOnTypeResolver
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeTypeResolver $nodeTypeResolver)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function resolve(Class_ $class, ObjectType $objectType) : array
|
||||
{
|
||||
$methodNames = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($class, function (Node $node) use(&$methodNames, $objectType) {
|
||||
if (!$node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeTypeResolver->isObjectType($node->var, $objectType)) {
|
||||
return null;
|
||||
}
|
||||
$name = $this->nodeNameResolver->getName($node->name);
|
||||
if ($name === null) {
|
||||
return null;
|
||||
}
|
||||
$methodNames[] = $name;
|
||||
});
|
||||
return \array_unique($methodNames);
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeManipulator;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\NodeTraverser;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeRemoval\NodeRemover;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
final class DependencyRemover
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeRemoval\NodeRemover
|
||||
*/
|
||||
private $nodeRemover;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeRemover $nodeRemover)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->nodeRemover = $nodeRemover;
|
||||
}
|
||||
public function removeByType(Class_ $class, ClassMethod $classMethod, Param $registryParam, string $type) : void
|
||||
{
|
||||
// remove constructor param: $managerRegistry
|
||||
foreach ($classMethod->params as $key => $param) {
|
||||
if ($param->type === null) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($param->type, $type)) {
|
||||
continue;
|
||||
}
|
||||
unset($classMethod->params[$key]);
|
||||
}
|
||||
$this->removeRegistryDependencyAssign($class, $classMethod, $registryParam);
|
||||
}
|
||||
private function removeRegistryDependencyAssign(Class_ $class, ClassMethod $classMethod, Param $registryParam) : void
|
||||
{
|
||||
foreach ((array) $classMethod->stmts as $constructorMethodStmt) {
|
||||
if (!$constructorMethodStmt instanceof Expression) {
|
||||
continue;
|
||||
}
|
||||
if (!$constructorMethodStmt->expr instanceof Assign) {
|
||||
continue;
|
||||
}
|
||||
/** @var Assign $assign */
|
||||
$assign = $constructorMethodStmt->expr;
|
||||
if (!$this->nodeNameResolver->areNamesEqual($assign->expr, $registryParam->var)) {
|
||||
continue;
|
||||
}
|
||||
$this->removeManagerRegistryProperty($class, $assign);
|
||||
// remove assign
|
||||
$this->nodeRemover->removeNodeFromStatements($classMethod, $constructorMethodStmt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
private function removeManagerRegistryProperty(Class_ $class, Assign $assign) : void
|
||||
{
|
||||
$removedPropertyName = $this->nodeNameResolver->getName($assign->var);
|
||||
if ($removedPropertyName === null) {
|
||||
return;
|
||||
}
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($class->stmts, function (Node $node) use($removedPropertyName) : ?int {
|
||||
if (!$node instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($node, $removedPropertyName)) {
|
||||
return null;
|
||||
}
|
||||
$this->nodeRemover->removeNode($node);
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\Doctrine\NodeAnalyzer\MethodCallNameOnTypeResolver;
|
||||
use Rector\Doctrine\NodeManipulator\DependencyRemover;
|
||||
use Rector\PostRector\Collector\PropertyToAddCollector;
|
||||
use Rector\PostRector\ValueObject\PropertyMetadata;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Doctrine\Tests\Rector\Class_\ManagerRegistryGetManagerToEntityManagerRector\ManagerRegistryGetManagerToEntityManagerRectorTest
|
||||
*/
|
||||
final class ManagerRegistryGetManagerToEntityManagerRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const GET_MANAGER = 'getManager';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const ENTITY_MANAGER = 'entityManager';
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeAnalyzer\MethodCallNameOnTypeResolver
|
||||
*/
|
||||
private $methodCallNameOnTypeResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeManipulator\DependencyRemover
|
||||
*/
|
||||
private $dependencyRemover;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PostRector\Collector\PropertyToAddCollector
|
||||
*/
|
||||
private $propertyToAddCollector;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Php\PhpVersionProvider
|
||||
*/
|
||||
private $phpVersionProvider;
|
||||
public function __construct(MethodCallNameOnTypeResolver $methodCallNameOnTypeResolver, DependencyRemover $dependencyRemover, PropertyToAddCollector $propertyToAddCollector, PhpVersionProvider $phpVersionProvider)
|
||||
{
|
||||
$this->methodCallNameOnTypeResolver = $methodCallNameOnTypeResolver;
|
||||
$this->dependencyRemover = $dependencyRemover;
|
||||
$this->propertyToAddCollector = $propertyToAddCollector;
|
||||
$this->phpVersionProvider = $phpVersionProvider;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Changes ManagerRegistry intermediate calls directly to EntityManager calls', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use Doctrine\Common\Persistence\ManagerRegistry;
|
||||
|
||||
class CustomRepository
|
||||
{
|
||||
/**
|
||||
* @var ManagerRegistry
|
||||
*/
|
||||
private $managerRegistry;
|
||||
|
||||
public function __construct(ManagerRegistry $managerRegistry)
|
||||
{
|
||||
$this->managerRegistry = $managerRegistry;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$entityManager = $this->managerRegistry->getManager();
|
||||
$someRepository = $entityManager->getRepository('Some');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class CustomRepository
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$someRepository = $this->entityManager->getRepository('Some');
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$constructorClassMethod = $node->getMethod(MethodName::CONSTRUCT);
|
||||
if (!$constructorClassMethod instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
// collect on registry method calls, so we know if the manager registry is needed
|
||||
$registryCalledMethods = $this->methodCallNameOnTypeResolver->resolve($node, new ObjectType('Doctrine\\Common\\Persistence\\ManagerRegistry'));
|
||||
if (!\in_array(self::GET_MANAGER, $registryCalledMethods, \true)) {
|
||||
return null;
|
||||
}
|
||||
$managerRegistryParam = $this->resolveManagerRegistryParam($constructorClassMethod);
|
||||
// no registry manager in the constructor
|
||||
if (!$managerRegistryParam instanceof Param) {
|
||||
return null;
|
||||
}
|
||||
if ($registryCalledMethods === [self::GET_MANAGER]) {
|
||||
// the manager registry is needed only get entity manager → we don't need it now
|
||||
$this->removeManagerRegistryDependency($node, $constructorClassMethod, $managerRegistryParam);
|
||||
}
|
||||
$this->replaceEntityRegistryVariableWithEntityManagerProperty($node);
|
||||
$this->removeAssignGetRepositoryCalls($node);
|
||||
// add entity manager via constructor
|
||||
$this->addConstructorDependencyWithProperty($node, $constructorClassMethod, self::ENTITY_MANAGER, new FullyQualifiedObjectType('Doctrine\\ORM\\EntityManagerInterface'));
|
||||
return $node;
|
||||
}
|
||||
private function resolveManagerRegistryParam(ClassMethod $classMethod) : ?Param
|
||||
{
|
||||
foreach ($classMethod->params as $param) {
|
||||
if ($param->type === null) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isName($param->type, 'Doctrine\\Common\\Persistence\\ManagerRegistry')) {
|
||||
continue;
|
||||
}
|
||||
return $param;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function removeManagerRegistryDependency(Class_ $class, ClassMethod $classMethod, Param $registryParam) : void
|
||||
{
|
||||
// remove constructor param: $managerRegistry
|
||||
foreach ($classMethod->params as $key => $param) {
|
||||
if ($param->type === null) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isName($param->type, 'Doctrine\\Common\\Persistence\\ManagerRegistry')) {
|
||||
continue;
|
||||
}
|
||||
unset($classMethod->params[$key]);
|
||||
}
|
||||
$this->dependencyRemover->removeByType($class, $classMethod, $registryParam, 'Doctrine\\Common\\Persistence\\ManagerRegistry');
|
||||
}
|
||||
/**
|
||||
* Before: $entityRegistry->
|
||||
*
|
||||
* After: $this->entityManager->
|
||||
*/
|
||||
private function replaceEntityRegistryVariableWithEntityManagerProperty(Class_ $class) : void
|
||||
{
|
||||
$this->traverseNodesWithCallable($class->stmts, function (Node $node) : ?PropertyFetch {
|
||||
if (!$node instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isObjectType($node, new ObjectType('Doctrine\\Common\\Persistence\\ObjectManager'))) {
|
||||
return null;
|
||||
}
|
||||
return new PropertyFetch(new Variable('this'), self::ENTITY_MANAGER);
|
||||
});
|
||||
}
|
||||
private function removeAssignGetRepositoryCalls(Class_ $class) : void
|
||||
{
|
||||
$this->traverseNodesWithCallable($class->stmts, function (Node $node) {
|
||||
if (!$node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isRegistryGetManagerMethodCall($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->removeNode($node);
|
||||
});
|
||||
}
|
||||
private function addConstructorDependencyWithProperty(Class_ $class, ClassMethod $classMethod, string $name, FullyQualifiedObjectType $fullyQualifiedObjectType) : void
|
||||
{
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::PROPERTY_PROMOTION)) {
|
||||
$assign = $this->nodeFactory->createPropertyAssignment($name);
|
||||
$classMethod->stmts[] = new Expression($assign);
|
||||
}
|
||||
$propertyMetadata = new PropertyMetadata($name, $fullyQualifiedObjectType, Class_::MODIFIER_PRIVATE);
|
||||
$this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
|
||||
}
|
||||
private function isRegistryGetManagerMethodCall(Assign $assign) : bool
|
||||
{
|
||||
if (!$assign->expr instanceof MethodCall) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->isObjectType($assign->expr->var, new ObjectType('Doctrine\\Common\\Persistence\\ManagerRegistry'))) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isName($assign->expr->name, self::GET_MANAGER);
|
||||
}
|
||||
}
|
|
@ -99,14 +99,13 @@ CODE_SAMPLE
|
|||
if ($proccesed === null) {
|
||||
continue;
|
||||
}
|
||||
/** @var int $key */
|
||||
$this->nodeRemover->removeStmt($node, $key);
|
||||
unset($node->stmts[$key]);
|
||||
}
|
||||
$node->stmts = \array_merge((array) $node->stmts, (array) $proccesed);
|
||||
$node->stmts = \array_merge($node->stmts, $proccesed);
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @return Expression[]|null
|
||||
* @return Node\Stmt[]|null
|
||||
*/
|
||||
private function processTryCatch(TryCatch $tryCatch) : ?array
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue