mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-19 06:52:51 +02:00
Updated Rector to commit 398baa2c6aa2af11d0a391bd0d2a71dfb71eebcf
398baa2c6a
[CI] Add doctrine rules in set check (#4505)
This commit is contained in:
parent
0a29dbd455
commit
ef7c42a7c7
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit3242976df14b603e76b7a1f1bed19dc3::getLoader();
|
||||
return ComposerAutoloaderInite631aee4475fe67fec461a471360a246::getLoader();
|
||||
|
11
vendor/composer/autoload_classmap.php
vendored
11
vendor/composer/autoload_classmap.php
vendored
@ -1738,13 +1738,13 @@ return array(
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\RemoveEmptyTableAttributeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\ChangeBigIntEntityPropertyToIntTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\CorrectDefaultTypesOnEntityPropertyRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\DoctrineTargetEntityStringToClassConstantRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\ImproveDoctrineCollectionDocTypeInEntityRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\MakeEntityDateTimePropertyDateTimeInterfaceRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromColumnTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromColumnTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromDoctrineCollectionRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToManyRelationTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToOneRelationTypeRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AssignPropertyFetchAnalyzer' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AssignPropertyFetchAnalyzer.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AttributeCleaner' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeCleaner.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AttributeFinder' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeFinder.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AttrinationFinder' => $vendorDir . '/rector/rector-doctrine/src/NodeAnalyzer/AttrinationFinder.php',
|
||||
@ -1753,16 +1753,11 @@ return array(
|
||||
'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',
|
||||
'Rector\\Doctrine\\NodeFactory\\ConstructClassMethodFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/ConstructClassMethodFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\ConstructorClassMethodAssignFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/ConstructorClassMethodAssignFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\EntityIdNodeFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/EntityIdNodeFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\ParamFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/ParamFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\RepositoryAssignFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/RepositoryAssignFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\RepositoryNodeFactory' => $vendorDir . '/rector/rector-doctrine/src/NodeFactory/RepositoryNodeFactory.php',
|
||||
'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\\IssetDimFetchCleaner' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/IssetDimFetchCleaner.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\NullabilityColumnPropertyTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/NullabilityColumnPropertyTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\PropertyTypeManipulator' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/PropertyTypeManipulator.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\ToManyRelationPropertyTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/ToManyRelationPropertyTypeResolver.php',
|
||||
@ -1771,8 +1766,6 @@ return array(
|
||||
'Rector\\Doctrine\\PhpDocParser\\DoctrineDocBlockResolver' => $vendorDir . '/rector/rector-doctrine/src/PhpDocParser/DoctrineDocBlockResolver.php',
|
||||
'Rector\\Doctrine\\PhpDoc\\ShortClassExpander' => $vendorDir . '/rector/rector-doctrine/src/PhpDoc/ShortClassExpander.php',
|
||||
'Rector\\Doctrine\\Rector\\ClassMethod\\ServiceEntityRepositoryParentCallToDIRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/ClassMethod/ServiceEntityRepositoryParentCallToDIRector.php',
|
||||
'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_\\MoveRepositoryFromParentToConstructorRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/MoveRepositoryFromParentToConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\RemoveRepositoryFromEntityAnnotationRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php',
|
||||
'Rector\\Doctrine\\Rector\\MethodCall\\ChangeCompositeExpressionAddMultipleWithWithRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php',
|
||||
@ -1780,7 +1773,6 @@ return array(
|
||||
'Rector\\Doctrine\\Rector\\MethodCall\\EntityAliasToClassConstantReferenceRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/MethodCall/EntityAliasToClassConstantReferenceRector.php',
|
||||
'Rector\\Doctrine\\Rector\\MethodCall\\ReplaceParentRepositoryCallsByRepositoryPropertyRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/MethodCall/ReplaceParentRepositoryCallsByRepositoryPropertyRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Param\\ReplaceLifecycleEventArgsByDedicatedEventArgsRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Param/ReplaceLifecycleEventArgsByDedicatedEventArgsRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\DoctrineTargetEntityStringToClassConstantRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php',
|
||||
'Rector\\Doctrine\\Set\\DoctrineSetList' => $vendorDir . '/rector/rector-doctrine/src/Set/DoctrineSetList.php',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\CollectionTypeFactory' => $vendorDir . '/rector/rector-doctrine/src/TypeAnalyzer/CollectionTypeFactory.php',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\CollectionTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/TypeAnalyzer/CollectionTypeResolver.php',
|
||||
@ -1788,7 +1780,6 @@ return array(
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\DoctrineCollectionTypeAnalyzer' => $vendorDir . '/rector/rector-doctrine/src/TypeAnalyzer/DoctrineCollectionTypeAnalyzer.php',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\TypeFinder' => $vendorDir . '/rector/rector-doctrine/src/TypeAnalyzer/TypeFinder.php',
|
||||
'Rector\\Doctrine\\Type\\RepositoryTypeFactory' => $vendorDir . '/rector/rector-doctrine/src/Type/RepositoryTypeFactory.php',
|
||||
'Rector\\Doctrine\\ValueObject\\AssignToPropertyFetch' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/AssignToPropertyFetch.php',
|
||||
'Rector\\DowngradePhp71\\Rector\\Array_\\SymmetricArrayDestructuringToListRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp71/Rector/Array_/SymmetricArrayDestructuringToListRector.php',
|
||||
'Rector\\DowngradePhp71\\Rector\\ClassConst\\DowngradeClassConstantVisibilityRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp71/Rector/ClassConst/DowngradeClassConstantVisibilityRector.php',
|
||||
'Rector\\DowngradePhp71\\Rector\\ConstFetch\\DowngradePhp71JsonConstRector' => $vendorDir . '/rector/rector-downgrade-php/rules/DowngradePhp71/Rector/ConstFetch/DowngradePhp71JsonConstRector.php',
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit3242976df14b603e76b7a1f1bed19dc3
|
||||
class ComposerAutoloaderInite631aee4475fe67fec461a471360a246
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit3242976df14b603e76b7a1f1bed19dc3
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3242976df14b603e76b7a1f1bed19dc3', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInite631aee4475fe67fec461a471360a246', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3242976df14b603e76b7a1f1bed19dc3', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite631aee4475fe67fec461a471360a246', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite631aee4475fe67fec461a471360a246::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite631aee4475fe67fec461a471360a246::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
19
vendor/composer/autoload_static.php
vendored
19
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
class ComposerStaticInite631aee4475fe67fec461a471360a246
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -1992,13 +1992,13 @@ class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\RemoveEmptyTableAttributeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\ChangeBigIntEntityPropertyToIntTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\CorrectDefaultTypesOnEntityPropertyRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\DoctrineTargetEntityStringToClassConstantRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\ImproveDoctrineCollectionDocTypeInEntityRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\MakeEntityDateTimePropertyDateTimeInterfaceRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromColumnTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromColumnTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromDoctrineCollectionRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToManyRelationTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\Rector\\Property\\TypedPropertyFromToOneRelationTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AssignPropertyFetchAnalyzer' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AssignPropertyFetchAnalyzer.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AttributeCleaner' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeCleaner.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AttributeFinder' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AttributeFinder.php',
|
||||
'Rector\\Doctrine\\NodeAnalyzer\\AttrinationFinder' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeAnalyzer/AttrinationFinder.php',
|
||||
@ -2007,16 +2007,11 @@ class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
'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',
|
||||
'Rector\\Doctrine\\NodeFactory\\ConstructClassMethodFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/ConstructClassMethodFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\ConstructorClassMethodAssignFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/ConstructorClassMethodAssignFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\EntityIdNodeFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/EntityIdNodeFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\ParamFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/ParamFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\RepositoryAssignFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/RepositoryAssignFactory.php',
|
||||
'Rector\\Doctrine\\NodeFactory\\RepositoryNodeFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeFactory/RepositoryNodeFactory.php',
|
||||
'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\\IssetDimFetchCleaner' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/IssetDimFetchCleaner.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\NullabilityColumnPropertyTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/NullabilityColumnPropertyTypeResolver.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\PropertyTypeManipulator' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/PropertyTypeManipulator.php',
|
||||
'Rector\\Doctrine\\NodeManipulator\\ToManyRelationPropertyTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/ToManyRelationPropertyTypeResolver.php',
|
||||
@ -2025,8 +2020,6 @@ class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
'Rector\\Doctrine\\PhpDocParser\\DoctrineDocBlockResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/PhpDocParser/DoctrineDocBlockResolver.php',
|
||||
'Rector\\Doctrine\\PhpDoc\\ShortClassExpander' => __DIR__ . '/..' . '/rector/rector-doctrine/src/PhpDoc/ShortClassExpander.php',
|
||||
'Rector\\Doctrine\\Rector\\ClassMethod\\ServiceEntityRepositoryParentCallToDIRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/ClassMethod/ServiceEntityRepositoryParentCallToDIRector.php',
|
||||
'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_\\MoveRepositoryFromParentToConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/MoveRepositoryFromParentToConstructorRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Class_\\RemoveRepositoryFromEntityAnnotationRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php',
|
||||
'Rector\\Doctrine\\Rector\\MethodCall\\ChangeCompositeExpressionAddMultipleWithWithRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php',
|
||||
@ -2034,7 +2027,6 @@ class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
'Rector\\Doctrine\\Rector\\MethodCall\\EntityAliasToClassConstantReferenceRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/MethodCall/EntityAliasToClassConstantReferenceRector.php',
|
||||
'Rector\\Doctrine\\Rector\\MethodCall\\ReplaceParentRepositoryCallsByRepositoryPropertyRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/MethodCall/ReplaceParentRepositoryCallsByRepositoryPropertyRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Param\\ReplaceLifecycleEventArgsByDedicatedEventArgsRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Param/ReplaceLifecycleEventArgsByDedicatedEventArgsRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\DoctrineTargetEntityStringToClassConstantRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php',
|
||||
'Rector\\Doctrine\\Set\\DoctrineSetList' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Set/DoctrineSetList.php',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\CollectionTypeFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/TypeAnalyzer/CollectionTypeFactory.php',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\CollectionTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/TypeAnalyzer/CollectionTypeResolver.php',
|
||||
@ -2042,7 +2034,6 @@ class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\DoctrineCollectionTypeAnalyzer' => __DIR__ . '/..' . '/rector/rector-doctrine/src/TypeAnalyzer/DoctrineCollectionTypeAnalyzer.php',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\TypeFinder' => __DIR__ . '/..' . '/rector/rector-doctrine/src/TypeAnalyzer/TypeFinder.php',
|
||||
'Rector\\Doctrine\\Type\\RepositoryTypeFactory' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Type/RepositoryTypeFactory.php',
|
||||
'Rector\\Doctrine\\ValueObject\\AssignToPropertyFetch' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/AssignToPropertyFetch.php',
|
||||
'Rector\\DowngradePhp71\\Rector\\Array_\\SymmetricArrayDestructuringToListRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp71/Rector/Array_/SymmetricArrayDestructuringToListRector.php',
|
||||
'Rector\\DowngradePhp71\\Rector\\ClassConst\\DowngradeClassConstantVisibilityRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp71/Rector/ClassConst/DowngradeClassConstantVisibilityRector.php',
|
||||
'Rector\\DowngradePhp71\\Rector\\ConstFetch\\DowngradePhp71JsonConstRector' => __DIR__ . '/..' . '/rector/rector-downgrade-php/rules/DowngradePhp71/Rector/ConstFetch/DowngradePhp71JsonConstRector.php',
|
||||
@ -3047,9 +3038,9 @@ class ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3242976df14b603e76b7a1f1bed19dc3::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite631aee4475fe67fec461a471360a246::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite631aee4475fe67fec461a471360a246::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite631aee4475fe67fec461a471360a246::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -1917,12 +1917,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "8e9e062ca22ee86c370f3aafbfc2030e73d8737f"
|
||||
"reference": "1128acf0334a7ed6753ed11155b6509c71d34f70"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/8e9e062ca22ee86c370f3aafbfc2030e73d8737f",
|
||||
"reference": "8e9e062ca22ee86c370f3aafbfc2030e73d8737f",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/1128acf0334a7ed6753ed11155b6509c71d34f70",
|
||||
"reference": "1128acf0334a7ed6753ed11155b6509c71d34f70",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1947,7 +1947,7 @@
|
||||
"tomasvotruba\/type-coverage": "^0.2",
|
||||
"tomasvotruba\/unused-public": "^0.1"
|
||||
},
|
||||
"time": "2023-07-13T13:34:42+00:00",
|
||||
"time": "2023-07-13T14:07:42+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
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 8e9e062'), '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 734960f'), '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 59b84b7'), '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 e788554'));
|
||||
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 1128acf'), '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 734960f'), '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 59b84b7'), '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 e788554'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
2
vendor/rector/rector-doctrine/composer.json
vendored
2
vendor/rector/rector-doctrine/composer.json
vendored
@ -49,7 +49,7 @@
|
||||
"check-cs": "vendor\/bin\/ecs check --ansi",
|
||||
"fix-cs": "vendor\/bin\/ecs check --fix --ansi",
|
||||
"docs": [
|
||||
"vendor\/bin\/rule-doc-generator generate src --output-file docs\/rector_rules_overview.md --ansi"
|
||||
"vendor\/bin\/rule-doc-generator generate src rules --output-file docs\/rector_rules_overview.md --ansi"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
|
@ -10,6 +10,7 @@ use Rector\Doctrine\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\ClassMethod\MakeEntitySetterNullabilityInSyncWithPropertyRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\ChangeBigIntEntityPropertyToIntTypeRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromColumnTypeRector;
|
||||
@ -28,6 +29,7 @@ return static function (RectorConfig $rectorConfig) : void {
|
||||
ChangeBigIntEntityPropertyToIntTypeRector::class,
|
||||
ImproveDoctrineCollectionDocTypeInEntityRector::class,
|
||||
RemoveEmptyTableAttributeRector::class,
|
||||
DoctrineTargetEntityStringToClassConstantRector::class,
|
||||
// typed properties in entities from annotations/attributes
|
||||
TypedPropertyFromColumnTypeRector::class,
|
||||
TypedPropertyFromToOneRelationTypeRector::class,
|
||||
|
@ -1,61 +1,10 @@
|
||||
# 23 Rules Overview
|
||||
|
||||
## AddEntityIdByConditionRector
|
||||
|
||||
Add entity id with annotations when meets condition
|
||||
|
||||
:wrench: **configure it!**
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\AddEntityIdByConditionRector`](../src/Rector/Class_/AddEntityIdByConditionRector.php)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Doctrine\Rector\Class_\AddEntityIdByConditionRector;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->ruleWithConfiguration(AddEntityIdByConditionRector::class, [
|
||||
AddEntityIdByConditionRector::DETECTED_TRAITS => [
|
||||
'Knp\DoctrineBehaviors\Model\Translatable\Translation',
|
||||
'Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait',
|
||||
],
|
||||
]);
|
||||
};
|
||||
```
|
||||
|
||||
↓
|
||||
|
||||
```diff
|
||||
+use Doctrine\ORM\Mapping as ORM;
|
||||
+
|
||||
class SomeClass
|
||||
{
|
||||
use SomeTrait;
|
||||
+
|
||||
+ /**
|
||||
+ * @ORM\Id
|
||||
+ * @ORM\Column(type="integer")
|
||||
+ * @ORM\GeneratedValue(strategy="AUTO")
|
||||
+ */
|
||||
+ private $id;
|
||||
+
|
||||
+ public function getId(): int
|
||||
+ {
|
||||
+ return $this->id;
|
||||
+ }
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
# 21 Rules Overview
|
||||
|
||||
## ChangeBigIntEntityPropertyToIntTypeRector
|
||||
|
||||
Change database type "bigint" for @var/type declaration to string
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\ChangeBigIntEntityPropertyToIntTypeRector`](../src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\ChangeBigIntEntityPropertyToIntTypeRector`](../rules/CodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -129,42 +78,11 @@ Change array to ArrayCollection in `setParameters()` method of query builder
|
||||
|
||||
<br>
|
||||
|
||||
## ClassAnnotationToNamedArgumentConstructorRector
|
||||
|
||||
Decorate classic array-based class annotation with named parameters
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\ClassAnnotationToNamedArgumentConstructorRector`](../src/Rector/Class_/ClassAnnotationToNamedArgumentConstructorRector.php)
|
||||
|
||||
```diff
|
||||
+use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
|
||||
+
|
||||
/**
|
||||
* @Annotation
|
||||
+ * @NamedArgumentConstructor
|
||||
*/
|
||||
class SomeAnnotation
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $foo;
|
||||
|
||||
- public function __construct(array $values)
|
||||
+ public function __construct(string $foo)
|
||||
{
|
||||
- $this->foo = $values['foo'];
|
||||
+ $this->foo = $foo;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## CorrectDefaultTypesOnEntityPropertyRector
|
||||
|
||||
Change default value types to match Doctrine annotation type
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector`](../src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector`](../rules/CodeQuality/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -188,7 +106,7 @@ Change default value types to match Doctrine annotation type
|
||||
|
||||
Convert targetEntities defined as String to <class>::class Constants in Doctrine Entities.
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\DoctrineTargetEntityStringToClassConstantRector`](../src/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector`](../rules/CodeQuality/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
@ -246,7 +164,7 @@ return static function (RectorConfig $rectorConfig): void {
|
||||
|
||||
Improve @var, `@param` and `@return` types for Doctrine collections to make them useful both for PHPStan and PHPStorm
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector`](../src/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector`](../rules/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
@ -272,7 +190,7 @@ Improve @var, `@param` and `@return` types for Doctrine collections to make them
|
||||
|
||||
Initialize collection property in Entity constructor
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\InitializeDefaultEntityCollectionRector`](../src/Rector/Class_/InitializeDefaultEntityCollectionRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Class_\InitializeDefaultEntityCollectionRector`](../rules/CodeQuality/Rector/Class_/InitializeDefaultEntityCollectionRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -300,7 +218,7 @@ Initialize collection property in Entity constructor
|
||||
|
||||
Make maker bundle generate DateTime property accept DateTimeInterface too
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector`](../src/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector`](../rules/CodeQuality/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -329,7 +247,7 @@ Make maker bundle generate DateTime property accept DateTimeInterface too
|
||||
|
||||
Make nullability in setter class method with respect to property
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\ClassMethod\MakeEntitySetterNullabilityInSyncWithPropertyRector`](../src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\ClassMethod\MakeEntitySetterNullabilityInSyncWithPropertyRector`](../rules/CodeQuality/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -359,7 +277,7 @@ Make nullability in setter class method with respect to property
|
||||
|
||||
Move default value for entity property to constructor, the safest place
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector`](../src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector`](../rules/CodeQuality/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -421,7 +339,7 @@ Turns parent EntityRepository class to constructor dependency
|
||||
|
||||
Remove empty Table attribute on entities because it's useless
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\RemoveEmptyTableAttributeRector`](../src/Rector/Class_/RemoveEmptyTableAttributeRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector`](../rules/CodeQuality/Rector/Class_/RemoveEmptyTableAttributeRector.php)
|
||||
|
||||
```diff
|
||||
<?php
|
||||
@ -535,7 +453,7 @@ Change ServiceEntityRepository to dependency injection, with repository property
|
||||
|
||||
Complete `@var` annotations or types based on @ORM\Column
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\TypedPropertyFromColumnTypeRector`](../src/Rector/Property/TypedPropertyFromColumnTypeRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromColumnTypeRector`](../rules/CodeQuality/Rector/Property/TypedPropertyFromColumnTypeRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -556,7 +474,7 @@ Complete `@var` annotations or types based on @ORM\Column
|
||||
|
||||
Add typed property based on Doctrine collection
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\TypedPropertyFromDoctrineCollectionRector`](../src/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromDoctrineCollectionRector`](../rules/CodeQuality/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -582,7 +500,7 @@ Add typed property based on Doctrine collection
|
||||
|
||||
Complete `@var` annotations or types based on @ORM\*toMany annotations or attributes
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\TypedPropertyFromToManyRelationTypeRector`](../src/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector`](../rules/CodeQuality/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@ -604,7 +522,7 @@ Complete `@var` annotations or types based on @ORM\*toMany annotations or attrib
|
||||
|
||||
Complete `@var` annotations or types based on @ORM\*toOne annotations or attributes
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\TypedPropertyFromToOneRelationTypeRector`](../src/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php)
|
||||
- class: [`Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToOneRelationTypeRector`](../rules/CodeQuality/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
2
vendor/rector/rector-doctrine/easy-ci.php
vendored
2
vendor/rector/rector-doctrine/easy-ci.php
vendored
@ -6,7 +6,7 @@ namespace RectorPrefix202307;
|
||||
use Rector\Doctrine\Rector\Class_\ClassAnnotationToNamedArgumentConstructorRector;
|
||||
use Rector\Doctrine\Rector\MethodCall\ChangeSetParametersArrayToArrayCollectionRector;
|
||||
use Rector\Doctrine\Rector\MethodCall\EntityAliasToClassConstantReferenceRector;
|
||||
use Rector\Doctrine\Rector\Property\DoctrineTargetEntityStringToClassConstantRector;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector;
|
||||
use RectorPrefix202307\Symplify\EasyCI\Config\EasyCIConfig;
|
||||
return static function (EasyCIConfig $easyCIConfig) : void {
|
||||
$easyCIConfig->paths([__DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/rules']);
|
||||
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector;
|
||||
|
||||
use Iterator;
|
||||
use RectorPrefix202307\PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
final class DoctrineTargetEntityStringToClassConstantRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(string $filePath) : void
|
||||
{
|
||||
$this->doTestFile($filePath);
|
||||
}
|
||||
public static function provideData() : Iterator
|
||||
{
|
||||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
public function provideConfigFilePath() : string
|
||||
{
|
||||
return __DIR__ . '/config/configured_rule.php';
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\{AnotherClass as AnotherClassA, AnotherClass as AnotherClassB};
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass as AnotherClassC;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\Embedded(class="AnotherClassA")
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AnotherClassB")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AnotherClassC")
|
||||
*/
|
||||
private readonly ?Collection $items2;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\{AnotherClass as AnotherClassA, AnotherClass as AnotherClassB};
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass as AnotherClassC;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\Embedded(class=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items2;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\Embedded(class="AnotherClass")
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items2;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items3;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(mappedBy="class", targetEntity="AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items4;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\Embedded(class=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items2;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items3;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(mappedBy="class", targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items4;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* Wrong Usage: @ORM\Embedded has a "class" attribute, but no "targetEntity"!
|
||||
*
|
||||
* @ORM\Embedded(targetEntity="AnotherClass")
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* Wrong Usage: @ORM\OneToMany has a "targetEntity" attribute, but no "class"!
|
||||
*
|
||||
* @ORM\OneToMany(class="AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* Wrong Usage: @ORM\Embedded has a "class" attribute, but no "targetEntity"!
|
||||
*
|
||||
* @ORM\Embedded(targetEntity="AnotherClass")
|
||||
*/
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* Wrong Usage: @ORM\OneToMany has a "targetEntity" attribute, but no "class"!
|
||||
*
|
||||
* @ORM\OneToMany(class="AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
/**
|
||||
* @see https://github.com/doctrine/orm/issues/8818
|
||||
*/
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App:AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
/**
|
||||
* @see https://github.com/doctrine/orm/issues/8818
|
||||
*/
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="App:AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="UnresolvableClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="UnresolvableClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass")
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Annotation;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=\Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)
|
||||
*/
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\{AnotherClass as AnotherClassA, AnotherClass as AnotherClassB};
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass as AnotherClassC;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\Embedded(class: "AnotherClassA")]
|
||||
private $other;
|
||||
|
||||
#[ORM\OneToMany(targetEntity: "AnotherClassB")]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
#[ORM\OneToMany(targetEntity: "AnotherClassC")]
|
||||
private readonly ?Collection $items2;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\{AnotherClass as AnotherClassA, AnotherClass as AnotherClassB};
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass as AnotherClassC;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\Embedded(class: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private $other;
|
||||
|
||||
#[ORM\OneToMany(targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
#[ORM\OneToMany(targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items2;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\Embedded(class: "AnotherClass")]
|
||||
private readonly ?Collection $other;
|
||||
#[ORM\OneToMany(targetEntity: "AnotherClass")]
|
||||
private readonly ?Collection $items;
|
||||
#[ORM\ManyToOne(targetEntity: "AnotherClass")]
|
||||
private readonly ?Collection $items2;
|
||||
#[ORM\ManyToMany(targetEntity: "AnotherClass")]
|
||||
private readonly ?Collection $items3;
|
||||
#[ORM\OneToOne(mappedBy: 'class', targetEntity: "AnotherClass")]
|
||||
private readonly ?Collection $items4;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\Embedded(class: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $other;
|
||||
#[ORM\OneToMany(targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items;
|
||||
#[ORM\ManyToOne(targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items2;
|
||||
#[ORM\ManyToMany(targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items3;
|
||||
#[ORM\OneToOne(mappedBy: 'class', targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items4;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* Wrong Usage: @ORM\Embedded has a "class" attribute, but no "targetEntity"!
|
||||
*/
|
||||
#[ORM\Embedded(targetEntity: "AnotherClass")]
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* Wrong Usage: @ORM\OneToMany has a "targetEntity" attribute, but no "class"!
|
||||
*/
|
||||
#[ORM\OneToMany(class: "AnotherClass")]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
/**
|
||||
* Wrong Usage: @ORM\Embedded has a "class" attribute, but no "targetEntity"!
|
||||
*/
|
||||
#[ORM\Embedded(targetEntity: "AnotherClass")]
|
||||
private $other;
|
||||
|
||||
/**
|
||||
* Wrong Usage: @ORM\OneToMany has a "targetEntity" attribute, but no "class"!
|
||||
*/
|
||||
#[ORM\OneToMany(class: "AnotherClass")]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: "App:AnotherClass")]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: "App:AnotherClass")]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: "UnresolvableClass")]
|
||||
private readonly ?Collection $items;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: "UnresolvableClass")]
|
||||
private readonly ?Collection $items;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: "Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass")]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Fixture\Attribute;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass;
|
||||
|
||||
final class MyEntity
|
||||
{
|
||||
#[ORM\ManyToOne(targetEntity: \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source\AnotherClass::class)]
|
||||
private readonly ?Collection $items;
|
||||
|
||||
public function addItem(AnotherClass $myOtherEntity): void
|
||||
{
|
||||
$this->items->add($myOtherEntity);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\Source;
|
||||
|
||||
final class AnotherClass
|
||||
{
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace RectorPrefix202307;
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Doctrine\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector;
|
||||
use Rector\Doctrine\Tests\ConfigList;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->import(ConfigList::MAIN);
|
||||
$rectorConfig->rule(DoctrineTargetEntityStringToClassConstantRector::class);
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Rector\Property;
|
||||
namespace Rector\Doctrine\CodeQuality\Rector\Property;
|
||||
|
||||
use RectorPrefix202307\Doctrine\ORM\Mapping\Embedded;
|
||||
use RectorPrefix202307\Doctrine\ORM\Mapping\ManyToMany;
|
||||
@ -22,7 +22,7 @@ use Rector\Doctrine\PhpDocParser\DoctrineClassAnnotationMatcher;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Doctrine\Tests\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\DoctrineTargetEntityStringToClassConstantRectorTest
|
||||
* @see \Rector\Doctrine\Tests\CodeQuality\Rector\Property\DoctrineTargetEntityStringToClassConstantRector\DoctrineTargetEntityStringToClassConstantRectorTest
|
||||
*/
|
||||
final class DoctrineTargetEntityStringToClassConstantRector extends AbstractRector
|
||||
{
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Doctrine\ValueObject\AssignToPropertyFetch;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
final class AssignPropertyFetchAnalyzer
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @return AssignToPropertyFetch[]
|
||||
*/
|
||||
public function resolveAssignToPropertyFetch(ClassMethod $classMethod) : array
|
||||
{
|
||||
/** @var Assign[] $assigns */
|
||||
$assigns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->stmts, Assign::class);
|
||||
$assignsToPropertyFetch = [];
|
||||
foreach ($assigns as $assign) {
|
||||
if (!$assign->var instanceof PropertyFetch) {
|
||||
continue;
|
||||
}
|
||||
$propertyFetch = $assign->var;
|
||||
/** @var string $propertyName */
|
||||
$propertyName = $this->nodeNameResolver->getName($propertyFetch);
|
||||
$assignsToPropertyFetch[] = new AssignToPropertyFetch($assign, $propertyFetch, $propertyName);
|
||||
}
|
||||
return $assignsToPropertyFetch;
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
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 Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
final class ConstructClassMethodFactory
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
||||
*/
|
||||
private $staticTypeMapper;
|
||||
public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, StaticTypeMapper $staticTypeMapper)
|
||||
{
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
}
|
||||
public function createFromPublicClassProperties(Class_ $class) : ?ClassMethod
|
||||
{
|
||||
$publicProperties = $this->resolvePublicProperties($class);
|
||||
if ($publicProperties === []) {
|
||||
return null;
|
||||
}
|
||||
$params = [];
|
||||
$assigns = [];
|
||||
foreach ($publicProperties as $publicProperty) {
|
||||
/** @var string $propertyName */
|
||||
$propertyName = $this->nodeNameResolver->getName($publicProperty);
|
||||
$params[] = $this->createParam($publicProperty, $propertyName);
|
||||
$assigns[] = $this->createAssign($propertyName);
|
||||
}
|
||||
$method = new Method(MethodName::CONSTRUCT);
|
||||
$method->makePublic();
|
||||
$method->addParams($params);
|
||||
$method->addStmts($assigns);
|
||||
return $method->getNode();
|
||||
}
|
||||
/**
|
||||
* @return Property[]
|
||||
*/
|
||||
private function resolvePublicProperties(Class_ $class) : array
|
||||
{
|
||||
$publicProperties = [];
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if (!$property->isPublic()) {
|
||||
continue;
|
||||
}
|
||||
$publicProperties[] = $property;
|
||||
}
|
||||
return $publicProperties;
|
||||
}
|
||||
private function createAssign(string $name) : Expression
|
||||
{
|
||||
$propertyFetch = new PropertyFetch(new Variable('this'), $name);
|
||||
$variable = new Variable($name);
|
||||
$assign = new Assign($propertyFetch, $variable);
|
||||
return new Expression($assign);
|
||||
}
|
||||
private function createParam(Property $property, string $propertyName) : Param
|
||||
{
|
||||
$propertyType = $this->nodeTypeResolver->getType($property);
|
||||
$propertyTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($propertyType, TypeKind::PROPERTY);
|
||||
$paramVariable = new Variable($propertyName);
|
||||
$param = new Param($paramVariable);
|
||||
$param->type = $propertyTypeNode;
|
||||
return $param;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeFactory;
|
||||
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
final class ConstructorClassMethodAssignFactory
|
||||
{
|
||||
/**
|
||||
* @param string[] $paramNames
|
||||
* @return Expression[]
|
||||
*/
|
||||
public function createFromParamNames(array $paramNames) : array
|
||||
{
|
||||
$expressions = [];
|
||||
foreach ($paramNames as $paramName) {
|
||||
$propertyFetch = new PropertyFetch(new Variable('this'), $paramName);
|
||||
$assign = new Assign($propertyFetch, new Variable($paramName));
|
||||
$expressions[] = new Expression($assign);
|
||||
}
|
||||
return $expressions;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeFactory;
|
||||
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
final class EntityIdNodeFactory
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
public function __construct(NodeFactory $nodeFactory, PhpDocInfoFactory $phpDocInfoFactory)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
}
|
||||
public function createIdProperty() : Property
|
||||
{
|
||||
$idProperty = $this->nodeFactory->createPrivateProperty('id');
|
||||
$this->decoratePropertyWithIdAnnotations($idProperty);
|
||||
return $idProperty;
|
||||
}
|
||||
private function decoratePropertyWithIdAnnotations(Property $property) : void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
// add @var int
|
||||
$identifierTypeNode = new IdentifierTypeNode('int');
|
||||
$varTagValueNode = new VarTagValueNode($identifierTypeNode, '', '');
|
||||
$phpDocInfo->addTagValueNode($varTagValueNode);
|
||||
// add @ORM\Id
|
||||
$phpDocTagNodes = [];
|
||||
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\Id', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\Id'), null, []));
|
||||
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\Column', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\Column'), null, [new ArrayItemNode(new StringNode('integer'), 'type')]));
|
||||
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\GeneratedValue', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\GeneratedValue'), null, [new ArrayItemNode(new StringNode('AUTO'), 'strategy')]));
|
||||
foreach ($phpDocTagNodes as $phpDocTagNode) {
|
||||
$phpDocInfo->addPhpDocTagNode($phpDocTagNode);
|
||||
}
|
||||
$phpDocInfo->markAsChanged();
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeFactory;
|
||||
|
||||
use PhpParser\Node\ComplexType;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\NullableType;
|
||||
use PhpParser\Node\Param;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\PhpParser\Node\NodeFactory;
|
||||
use Rector\Doctrine\ValueObject\AssignToPropertyFetch;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||
final class ParamFactory
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
||||
*/
|
||||
private $staticTypeMapper;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
public function __construct(NodeTypeResolver $nodeTypeResolver, StaticTypeMapper $staticTypeMapper, NodeNameResolver $nodeNameResolver, NodeFactory $nodeFactory)
|
||||
{
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
$this->staticTypeMapper = $staticTypeMapper;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
/**
|
||||
* @param AssignToPropertyFetch[] $assignsToPropertyFetch
|
||||
* @param string[] $optionalParamNames
|
||||
* @return Param[]
|
||||
*/
|
||||
public function createFromAssignsToPropertyFetch(array $assignsToPropertyFetch, array $optionalParamNames) : array
|
||||
{
|
||||
$params = [];
|
||||
foreach ($assignsToPropertyFetch as $assignToPropertyFetch) {
|
||||
$propertyFetch = $assignToPropertyFetch->getPropertyFetch();
|
||||
$params[] = $this->createFromPropertyFetch($propertyFetch, $optionalParamNames);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
/**
|
||||
* @param string[] $optionalParamNames
|
||||
*/
|
||||
private function createFromPropertyFetch(PropertyFetch $propertyFetch, array $optionalParamNames) : Param
|
||||
{
|
||||
$propertyName = $this->nodeNameResolver->getName($propertyFetch->name);
|
||||
if ($propertyName === null) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
$variable = new Variable($propertyName);
|
||||
$param = new Param($variable);
|
||||
$paramType = $this->nodeTypeResolver->getType($propertyFetch);
|
||||
$paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($paramType, TypeKind::PARAM);
|
||||
// the param is optional - make it nullable
|
||||
if (\in_array($propertyName, $optionalParamNames, \true)) {
|
||||
if (!$paramTypeNode instanceof ComplexType && $paramTypeNode !== null) {
|
||||
$param->type = new NullableType($paramTypeNode);
|
||||
}
|
||||
$param->default = $this->nodeFactory->createNull();
|
||||
}
|
||||
if ($param->type === null) {
|
||||
$param->type = $paramTypeNode;
|
||||
}
|
||||
return $param;
|
||||
}
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\NodeManipulator;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\Isset_;
|
||||
use PhpParser\Node\Expr\Throw_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\If_;
|
||||
use PhpParser\Node\Stmt\Throw_ as ThrowStmt;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\Core\PhpParser\Node\Value\ValueResolver;
|
||||
final class IssetDimFetchCleaner
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
|
||||
*/
|
||||
private $valueResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, ValueResolver $valueResolver, NodeComparator $nodeComparator)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->valueResolver = $valueResolver;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function resolveOptionalParamNames(ClassMethod $classMethod, Variable $paramVariable) : array
|
||||
{
|
||||
$optionalParamNames = [];
|
||||
if ($classMethod->stmts === null) {
|
||||
return [];
|
||||
}
|
||||
foreach ($classMethod->stmts as $stmt) {
|
||||
if (!$stmt instanceof If_) {
|
||||
continue;
|
||||
}
|
||||
$if = $stmt;
|
||||
/** @var Isset_|null $isset */
|
||||
$isset = $this->betterNodeFinder->findFirstInstanceOf($if->cond, Isset_::class);
|
||||
if (!$isset instanceof Isset_) {
|
||||
continue;
|
||||
}
|
||||
foreach ($isset->vars as $var) {
|
||||
$dimFetchValue = $this->matchArrayDimFetchValue($var, $paramVariable);
|
||||
if (!\is_string($dimFetchValue)) {
|
||||
continue;
|
||||
}
|
||||
// is required or optional?
|
||||
if ($this->isRequiredIsset($if)) {
|
||||
// contains exception or required param → skip
|
||||
continue;
|
||||
}
|
||||
// else optional param
|
||||
$optionalParamNames[] = $dimFetchValue;
|
||||
}
|
||||
}
|
||||
return $optionalParamNames;
|
||||
}
|
||||
public function removeArrayDimFetchIssets(ClassMethod $classMethod, Variable $paramVariable) : void
|
||||
{
|
||||
if ($classMethod->stmts === null) {
|
||||
return;
|
||||
}
|
||||
foreach ($classMethod->stmts as $key => $stmt) {
|
||||
if (!$stmt instanceof If_) {
|
||||
continue;
|
||||
}
|
||||
$if = $stmt;
|
||||
/** @var Isset_|null $isset */
|
||||
$isset = $this->betterNodeFinder->findFirstInstanceOf($if->cond, Isset_::class);
|
||||
if (!$isset instanceof Isset_) {
|
||||
continue;
|
||||
}
|
||||
foreach ($isset->vars as $var) {
|
||||
if (!$this->isArrayDimFetchOnVariable($var, $paramVariable)) {
|
||||
continue;
|
||||
}
|
||||
// remove if stmt, this check is not part of __constuct() contract
|
||||
unset($classMethod->stmts[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
private function isArrayDimFetchOnVariable(Expr $expr, Variable $desiredVariable) : bool
|
||||
{
|
||||
if (!$expr instanceof ArrayDimFetch) {
|
||||
return \false;
|
||||
}
|
||||
return $this->nodeComparator->areNodesEqual($desiredVariable, $expr->var);
|
||||
}
|
||||
/**
|
||||
* @return mixed|mixed[]|string|null
|
||||
*/
|
||||
private function matchArrayDimFetchValue(Expr $expr, Variable $variable)
|
||||
{
|
||||
if (!$expr instanceof ArrayDimFetch) {
|
||||
return null;
|
||||
}
|
||||
if (!$expr->dim instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isArrayDimFetchOnVariable($expr, $variable)) {
|
||||
return null;
|
||||
}
|
||||
return $this->valueResolver->getValue($expr->dim);
|
||||
}
|
||||
private function isRequiredIsset(If_ $if) : bool
|
||||
{
|
||||
return $this->betterNodeFinder->hasInstancesOf($if->stmts, [Throw_::class, ThrowStmt::class]);
|
||||
}
|
||||
}
|
@ -1,144 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
|
||||
use Rector\Core\NodeManipulator\ClassInsertManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Doctrine\NodeFactory\EntityIdNodeFactory;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix202307\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Doctrine\Tests\Rector\Class_\AddEntityIdByConditionRector\AddEntityIdByConditionRectorTest
|
||||
*/
|
||||
final class AddEntityIdByConditionRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeFactory\EntityIdNodeFactory
|
||||
*/
|
||||
private $entityIdNodeFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\ClassInsertManipulator
|
||||
*/
|
||||
private $classInsertManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\ClassAnalyzer
|
||||
*/
|
||||
private $classAnalyzer;
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const DETECTED_TRAITS = 'detected_traits';
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $detectedTraits = [];
|
||||
public function __construct(EntityIdNodeFactory $entityIdNodeFactory, ClassInsertManipulator $classInsertManipulator, ReflectionProvider $reflectionProvider, ClassAnalyzer $classAnalyzer)
|
||||
{
|
||||
$this->entityIdNodeFactory = $entityIdNodeFactory;
|
||||
$this->classInsertManipulator = $classInsertManipulator;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->classAnalyzer = $classAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Add entity id with annotations when meets condition', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
use SomeTrait;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
use SomeTrait;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::DETECTED_TRAITS => ['Knp\\DoctrineBehaviors\\Model\\Translatable\\Translation', 'Knp\\DoctrineBehaviors\\Model\\Translatable\\TranslationTrait']])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$idProperty = $this->entityIdNodeFactory->createIdProperty();
|
||||
$this->classInsertManipulator->addAsFirstMethod($node, $idProperty);
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$detectTraits = $configuration[self::DETECTED_TRAITS] ?? $configuration;
|
||||
Assert::isArray($detectTraits);
|
||||
Assert::allString($detectTraits);
|
||||
$this->detectedTraits = $detectTraits;
|
||||
}
|
||||
private function shouldSkip(Class_ $class) : bool
|
||||
{
|
||||
if ($this->classAnalyzer->isAnonymousClass($class)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$this->isTraitMatch($class)) {
|
||||
return \true;
|
||||
}
|
||||
return (bool) $class->getProperty('id');
|
||||
}
|
||||
private function isTraitMatch(Class_ $class) : bool
|
||||
{
|
||||
$className = $this->getName($class);
|
||||
if ($className === null) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->reflectionProvider->hasClass($className)) {
|
||||
return \false;
|
||||
}
|
||||
$classReflection = $this->reflectionProvider->getClass($className);
|
||||
foreach ($this->detectedTraits as $detectedTrait) {
|
||||
if ($classReflection->hasTraitUse($detectedTrait)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\NodeManipulator\ClassInsertManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\Doctrine\NodeAnalyzer\AssignPropertyFetchAnalyzer;
|
||||
use Rector\Doctrine\NodeFactory\ConstructClassMethodFactory;
|
||||
use Rector\Doctrine\NodeFactory\ConstructorClassMethodAssignFactory;
|
||||
use Rector\Doctrine\NodeFactory\ParamFactory;
|
||||
use Rector\Doctrine\NodeManipulator\IssetDimFetchCleaner;
|
||||
use Rector\Doctrine\ValueObject\AssignToPropertyFetch;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://github.com/doctrine/annotations/blob/1.13.x/docs/en/custom.rst#optional-constructors-with-named-parameters
|
||||
*
|
||||
* @see \Rector\Doctrine\Tests\Rector\Class_\ClassAnnotationToNamedArgumentConstructorRector\ClassAnnotationToNamedArgumentConstructorRectorTest
|
||||
*/
|
||||
final class ClassAnnotationToNamedArgumentConstructorRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeFactory\ParamFactory
|
||||
*/
|
||||
private $paramFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeFactory\ConstructClassMethodFactory
|
||||
*/
|
||||
private $constructClassMethodFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\ClassInsertManipulator
|
||||
*/
|
||||
private $classInsertManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeAnalyzer\AssignPropertyFetchAnalyzer
|
||||
*/
|
||||
private $assignPropertyFetchAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeManipulator\IssetDimFetchCleaner
|
||||
*/
|
||||
private $issetDimFetchCleaner;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\NodeFactory\ConstructorClassMethodAssignFactory
|
||||
*/
|
||||
private $constructorClassMethodAssignFactory;
|
||||
public function __construct(ParamFactory $paramFactory, ConstructClassMethodFactory $constructClassMethodFactory, ClassInsertManipulator $classInsertManipulator, AssignPropertyFetchAnalyzer $assignPropertyFetchAnalyzer, IssetDimFetchCleaner $issetDimFetchCleaner, ConstructorClassMethodAssignFactory $constructorClassMethodAssignFactory)
|
||||
{
|
||||
$this->paramFactory = $paramFactory;
|
||||
$this->constructClassMethodFactory = $constructClassMethodFactory;
|
||||
$this->classInsertManipulator = $classInsertManipulator;
|
||||
$this->assignPropertyFetchAnalyzer = $assignPropertyFetchAnalyzer;
|
||||
$this->issetDimFetchCleaner = $issetDimFetchCleaner;
|
||||
$this->constructorClassMethodAssignFactory = $constructorClassMethodAssignFactory;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Decorate classic array-based class annotation with named parameters', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class SomeAnnotation
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $foo;
|
||||
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->foo = $values['foo'];
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @NamedArgumentConstructor
|
||||
*/
|
||||
class SomeAnnotation
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $foo;
|
||||
|
||||
public function __construct(string $foo)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
|
||||
if (!$phpDocInfo instanceof PhpDocInfo) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkipPhpDocInfo($phpDocInfo)) {
|
||||
return null;
|
||||
}
|
||||
$doctrineAnnotationTagValueNode = new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\Common\\Annotations\\Annotation\\NamedArgumentConstructor'));
|
||||
$phpDocInfo->addTagValueNode($doctrineAnnotationTagValueNode);
|
||||
$classMethod = $node->getMethod(MethodName::CONSTRUCT);
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
return $this->decorateClassWithAssignClassMethod($node);
|
||||
}
|
||||
if (!$this->hasSingleArrayParam($classMethod)) {
|
||||
return null;
|
||||
}
|
||||
/** @var Variable $paramVariable */
|
||||
$paramVariable = $classMethod->params[0]->var;
|
||||
$optionalParamNames = $this->issetDimFetchCleaner->resolveOptionalParamNames($classMethod, $paramVariable);
|
||||
$assignsToPropertyFetch = $this->assignPropertyFetchAnalyzer->resolveAssignToPropertyFetch($classMethod);
|
||||
$this->replaceAssignsByParam($assignsToPropertyFetch);
|
||||
$this->issetDimFetchCleaner->removeArrayDimFetchIssets($classMethod, $paramVariable);
|
||||
$classMethod->params = $this->paramFactory->createFromAssignsToPropertyFetch($assignsToPropertyFetch, $optionalParamNames);
|
||||
// include assigns for optional params - these do not have assign in the root, as they're hidden in if isset/check
|
||||
// so we have to add them
|
||||
$assigns = $this->constructorClassMethodAssignFactory->createFromParamNames($optionalParamNames);
|
||||
if ($assigns !== []) {
|
||||
$classMethod->stmts = \array_merge((array) $classMethod->stmts, $assigns);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
private function shouldSkipPhpDocInfo(PhpDocInfo $phpDocInfo) : bool
|
||||
{
|
||||
if (!$phpDocInfo->hasByNames(['annotation', 'Annotation'])) {
|
||||
return \true;
|
||||
}
|
||||
return $phpDocInfo->hasByAnnotationClass('Doctrine\\Common\\Annotations\\Annotation\\NamedArgumentConstructor');
|
||||
}
|
||||
private function hasSingleArrayParam(ClassMethod $classMethod) : bool
|
||||
{
|
||||
if (\count($classMethod->params) !== 1) {
|
||||
return \false;
|
||||
}
|
||||
$onlyParam = $classMethod->params[0];
|
||||
// change array to properites
|
||||
if (!$onlyParam->type instanceof Node) {
|
||||
return \false;
|
||||
}
|
||||
$paramType = $this->nodeTypeResolver->getType($onlyParam);
|
||||
// we have a match
|
||||
return $paramType instanceof ArrayType;
|
||||
}
|
||||
/**
|
||||
* @param AssignToPropertyFetch[] $assignsToPropertyFetch
|
||||
*/
|
||||
private function replaceAssignsByParam(array $assignsToPropertyFetch) : void
|
||||
{
|
||||
foreach ($assignsToPropertyFetch as $assignToPropertyFetch) {
|
||||
$assign = $assignToPropertyFetch->getAssign();
|
||||
$assign->expr = new Variable($assignToPropertyFetch->getPropertyName());
|
||||
}
|
||||
}
|
||||
private function decorateClassWithAssignClassMethod(Class_ $class) : ?\PhpParser\Node\Stmt\Class_
|
||||
{
|
||||
// complete public properties
|
||||
$constructClassMethod = $this->constructClassMethodFactory->createFromPublicClassProperties($class);
|
||||
if (!$constructClassMethod instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
$this->classInsertManipulator->addAsFirstMethod($class, $constructClassMethod);
|
||||
return $class;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\ValueObject;
|
||||
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
final class AssignToPropertyFetch
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PhpParser\Node\Expr\Assign
|
||||
*/
|
||||
private $assign;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PhpParser\Node\Expr\PropertyFetch
|
||||
*/
|
||||
private $propertyFetch;
|
||||
/**
|
||||
* @readonly
|
||||
* @var string
|
||||
*/
|
||||
private $propertyName;
|
||||
public function __construct(Assign $assign, PropertyFetch $propertyFetch, string $propertyName)
|
||||
{
|
||||
$this->assign = $assign;
|
||||
$this->propertyFetch = $propertyFetch;
|
||||
$this->propertyName = $propertyName;
|
||||
}
|
||||
public function getAssign() : Assign
|
||||
{
|
||||
return $this->assign;
|
||||
}
|
||||
public function getPropertyFetch() : PropertyFetch
|
||||
{
|
||||
return $this->propertyFetch;
|
||||
}
|
||||
public function getPropertyName() : string
|
||||
{
|
||||
return $this->propertyName;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user