mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-04 02:10:51 +00:00
Updated Rector to commit 7916cd907d55e32e9711ee7dc07ed45016eff152
7916cd907d
[DX] Remove doctrine collection responsibility to TypedPropertyRector (#2640)
This commit is contained in:
parent
331fec3c26
commit
e86c09a91b
|
@ -20,7 +20,6 @@ use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
|
|||
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
|
||||
use Rector\Php74\Guard\MakePropertyTypedGuard;
|
||||
use Rector\Php74\TypeAnalyzer\ObjectTypeAnalyzer;
|
||||
use Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector;
|
||||
use Rector\TypeDeclaration\TypeInferer\VarDocPropertyTypeInferer;
|
||||
|
@ -32,8 +31,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
* @changelog https://wiki.php.net/rfc/typed_properties_v2#proposal
|
||||
*
|
||||
* @see \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\TypedPropertyRectorTest
|
||||
* @see \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\ClassLikeTypesOnlyTest
|
||||
* @see \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\DoctrineTypedPropertyRectorTest
|
||||
* @see \Rector\Tests\Php74\Rector\Property\TypedPropertyRector\ImportedTest
|
||||
*/
|
||||
final class TypedPropertyRector extends AbstractScopeAwareRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
|
||||
|
@ -63,11 +60,6 @@ final class TypedPropertyRector extends AbstractScopeAwareRector implements Allo
|
|||
* @var \Rector\VendorLocker\VendorLockResolver
|
||||
*/
|
||||
private $vendorLockResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer
|
||||
*/
|
||||
private $doctrineTypeAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover
|
||||
|
@ -93,11 +85,10 @@ final class TypedPropertyRector extends AbstractScopeAwareRector implements Allo
|
|||
* @var \Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector
|
||||
*/
|
||||
private $constructorAssignDetector;
|
||||
public function __construct(VarDocPropertyTypeInferer $varDocPropertyTypeInferer, VendorLockResolver $vendorLockResolver, DoctrineTypeAnalyzer $doctrineTypeAnalyzer, VarTagRemover $varTagRemover, FamilyRelationsAnalyzer $familyRelationsAnalyzer, ObjectTypeAnalyzer $objectTypeAnalyzer, MakePropertyTypedGuard $makePropertyTypedGuard, ConstructorAssignDetector $constructorAssignDetector)
|
||||
public function __construct(VarDocPropertyTypeInferer $varDocPropertyTypeInferer, VendorLockResolver $vendorLockResolver, VarTagRemover $varTagRemover, FamilyRelationsAnalyzer $familyRelationsAnalyzer, ObjectTypeAnalyzer $objectTypeAnalyzer, MakePropertyTypedGuard $makePropertyTypedGuard, ConstructorAssignDetector $constructorAssignDetector)
|
||||
{
|
||||
$this->varDocPropertyTypeInferer = $varDocPropertyTypeInferer;
|
||||
$this->vendorLockResolver = $vendorLockResolver;
|
||||
$this->doctrineTypeAnalyzer = $doctrineTypeAnalyzer;
|
||||
$this->varTagRemover = $varTagRemover;
|
||||
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
|
||||
$this->objectTypeAnalyzer = $objectTypeAnalyzer;
|
||||
|
@ -161,7 +152,6 @@ CODE_SAMPLE
|
|||
$varDocType = $propertyType->getVarType();
|
||||
$propertyTypeNode = $propertyType->getPropertyTypeNode();
|
||||
$this->varTagRemover->removeVarPhpTagValueNodeIfNotComment($node, $varDocType);
|
||||
$this->removeDefaultValueForDoctrineCollection($node, $varDocType);
|
||||
$this->addDefaultValueNullForNullableType($node, $varDocType);
|
||||
$node->type = $propertyTypeNode;
|
||||
return $node;
|
||||
|
@ -190,14 +180,6 @@ CODE_SAMPLE
|
|||
}
|
||||
return $this->vendorLockResolver->isPropertyTypeChangeVendorLockedIn($property);
|
||||
}
|
||||
private function removeDefaultValueForDoctrineCollection(Property $property, Type $propertyType) : void
|
||||
{
|
||||
if (!$this->doctrineTypeAnalyzer->isDoctrineCollectionWithIterableUnionType($propertyType)) {
|
||||
return;
|
||||
}
|
||||
$onlyProperty = $property->props[0];
|
||||
$onlyProperty->default = null;
|
||||
}
|
||||
private function addDefaultValueNullForNullableType(Property $property, Type $propertyType) : void
|
||||
{
|
||||
if (!TypeCombinator::containsNull($propertyType)) {
|
||||
|
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'e6cc503e24bbbc362d6e05b4f4a322ff97c09457';
|
||||
public const PACKAGE_VERSION = '7916cd907d55e32e9711ee7dc07ed45016eff152';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-07-06 19:18:29';
|
||||
public const RELEASE_DATE = '2022-07-06 19:34:29';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitcf7a9ee10b9d0ab9f5be42c9a1db419b::getLoader();
|
||||
return ComposerAutoloaderInit273448b07d96eb4044df90c5599a04ff::getLoader();
|
||||
|
|
2
vendor/composer/autoload_classmap.php
vendored
2
vendor/composer/autoload_classmap.php
vendored
|
@ -1808,12 +1808,14 @@ return array(
|
|||
'Rector\\Doctrine\\Rector\\Property\\MakeEntityDateTimePropertyDateTimeInterfaceRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\RemoveRedundantDefaultPropertyAnnotationValuesRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromColumnTypeRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromColumnTypeRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromDoctrineCollectionRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromToManyRelationTypeRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromToOneRelationTypeRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromToOneRelationTypeRector.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',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\CollectionVarTagValueNodeResolver' => $vendorDir . '/rector/rector-doctrine/src/TypeAnalyzer/CollectionVarTagValueNodeResolver.php',
|
||||
'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\\ArgName' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/ArgName.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitcf7a9ee10b9d0ab9f5be42c9a1db419b
|
||||
class ComposerAutoloaderInit273448b07d96eb4044df90c5599a04ff
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInitcf7a9ee10b9d0ab9f5be42c9a1db419b
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcf7a9ee10b9d0ab9f5be42c9a1db419b', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit273448b07d96eb4044df90c5599a04ff', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcf7a9ee10b9d0ab9f5be42c9a1db419b', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit273448b07d96eb4044df90c5599a04ff', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit273448b07d96eb4044df90c5599a04ff::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit273448b07d96eb4044df90c5599a04ff::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequirecf7a9ee10b9d0ab9f5be42c9a1db419b($fileIdentifier, $file);
|
||||
composerRequire273448b07d96eb4044df90c5599a04ff($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInitcf7a9ee10b9d0ab9f5be42c9a1db419b
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequirecf7a9ee10b9d0ab9f5be42c9a1db419b($fileIdentifier, $file)
|
||||
function composerRequire273448b07d96eb4044df90c5599a04ff($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
10
vendor/composer/autoload_static.php
vendored
10
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b
|
||||
class ComposerStaticInit273448b07d96eb4044df90c5599a04ff
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -2115,12 +2115,14 @@ class ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b
|
|||
'Rector\\Doctrine\\Rector\\Property\\MakeEntityDateTimePropertyDateTimeInterfaceRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/MakeEntityDateTimePropertyDateTimeInterfaceRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\RemoveRedundantDefaultPropertyAnnotationValuesRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/RemoveRedundantDefaultPropertyAnnotationValuesRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromColumnTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromColumnTypeRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromDoctrineCollectionRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromToManyRelationTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromToManyRelationTypeRector.php',
|
||||
'Rector\\Doctrine\\Rector\\Property\\TypedPropertyFromToOneRelationTypeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromToOneRelationTypeRector.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',
|
||||
'Rector\\Doctrine\\TypeAnalyzer\\CollectionVarTagValueNodeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/TypeAnalyzer/CollectionVarTagValueNodeResolver.php',
|
||||
'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\\ArgName' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/ArgName.php',
|
||||
|
@ -3410,9 +3412,9 @@ class ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcf7a9ee10b9d0ab9f5be42c9a1db419b::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit273448b07d96eb4044df90c5599a04ff::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit273448b07d96eb4044df90c5599a04ff::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit273448b07d96eb4044df90c5599a04ff::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -1923,12 +1923,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "c0ff68c2e0b13c920c1c8a207e262a3909b6cf5e"
|
||||
"reference": "d61cca45c838fe5908bbc88327b2bc35dbc9cc74"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/c0ff68c2e0b13c920c1c8a207e262a3909b6cf5e",
|
||||
"reference": "c0ff68c2e0b13c920c1c8a207e262a3909b6cf5e",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/d61cca45c838fe5908bbc88327b2bc35dbc9cc74",
|
||||
"reference": "d61cca45c838fe5908bbc88327b2bc35dbc9cc74",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1953,7 +1953,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.0",
|
||||
"symplify\/vendor-patches": "^11.0"
|
||||
},
|
||||
"time": "2022-07-06T19:11:45+00:00",
|
||||
"time": "2022-07-06T19:28:32+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-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 86ab8c3'), '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 c0ff68c'), '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 97f49a2'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 644d45b'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 425881a'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main bee7c19'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d826618'), '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 81f779a'), '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 d4e61a1'));
|
||||
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 86ab8c3'), '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 d61cca4'), '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 97f49a2'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 644d45b'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 425881a'), 'rector/rector-nette' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-nette', 'relative_install_path' => '../../rector-nette', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main bee7c19'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main d826618'), '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 81f779a'), '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 d4e61a1'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Rector\Doctrine\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRect
|
|||
use Rector\Doctrine\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector;
|
||||
use Rector\Doctrine\Rector\Property\RemoveRedundantDefaultPropertyAnnotationValuesRector;
|
||||
use Rector\Doctrine\Rector\Property\TypedPropertyFromColumnTypeRector;
|
||||
use Rector\Doctrine\Rector\Property\TypedPropertyFromDoctrineCollectionRector;
|
||||
use Rector\Doctrine\Rector\Property\TypedPropertyFromToManyRelationTypeRector;
|
||||
use Rector\Doctrine\Rector\Property\TypedPropertyFromToOneRelationTypeRector;
|
||||
use Rector\Privatization\Rector\MethodCall\ReplaceStringWithClassConstantRector;
|
||||
|
@ -38,6 +39,7 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$rectorConfig->rule(TypedPropertyFromColumnTypeRector::class);
|
||||
$rectorConfig->rule(TypedPropertyFromToOneRelationTypeRector::class);
|
||||
$rectorConfig->rule(TypedPropertyFromToManyRelationTypeRector::class);
|
||||
$rectorConfig->rule(TypedPropertyFromDoctrineCollectionRector::class);
|
||||
$rectorConfig->ruleWithConfiguration(AttributeKeyToClassConstFetchRector::class, [new AttributeKeyToClassConstFetch('Doctrine\\ORM\\Mapping\\Column', 'type', 'Doctrine\\DBAL\\Types\\Types', ['array' => 'ARRAY', 'ascii_string' => 'ASCII_STRING', 'bigint' => 'BIGINT', 'binary' => 'BINARY', 'blob' => 'BLOB', 'boolean' => 'BOOLEAN', 'date' => 'DATE_MUTABLE', 'date_immutable' => 'DATE_IMMUTABLE', 'dateinterval' => 'DATEINTERVAL', 'datetime' => 'DATETIME_MUTABLE', 'datetime_immutable' => 'DATETIME_IMMUTABLE', 'datetimetz' => 'DATETIMETZ_MUTABLE', 'datetimetz_immutable' => 'DATETIMETZ_IMMUTABLE', 'decimal' => 'DECIMAL', 'float' => 'FLOAT', 'guid' => 'GUID', 'integer' => 'INTEGER', 'json' => 'JSON', 'object' => 'OBJECT', 'simple_array' => 'SIMPLE_ARRAY', 'smallint' => 'SMALLINT', 'string' => 'STRING', 'text' => 'TEXT', 'time' => 'TIME_MUTABLE', 'time_immutable' => 'TIME_IMMUTABLE'])]);
|
||||
$rectorConfig->ruleWithConfiguration(ReplaceStringWithClassConstantRector::class, [new ReplaceStringWithClassConstant('Doctrine\\ORM\\QueryBuilder', 'orderBy', 1, 'Doctrine\\Common\\Collections\\Criteria', \true), new ReplaceStringWithClassConstant('Doctrine\\ORM\\QueryBuilder', 'addOrderBy', 1, 'Doctrine\\Common\\Collections\\Criteria', \true)]);
|
||||
$rectorConfig->ruleWithConfiguration(ServiceGetterToConstructorInjectionRector::class, [new ServiceGetterToConstructorInjection('Doctrine\\Common\\Persistence\\ManagerRegistry', 'getConnection', 'Doctrine\\DBAL\\Connection'), new ServiceGetterToConstructorInjection('Doctrine\\ORM\\EntityManagerInterface', 'getConfiguration', 'Doctrine\\ORM\\Configuration')]);
|
||||
|
|
101
vendor/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php
vendored
Normal file
101
vendor/rector/rector-doctrine/src/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\Doctrine\TypeAnalyzer\DoctrineCollectionTypeAnalyzer;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Doctrine\Tests\Rector\Property\TypedPropertyFromDoctrineCollectionRector\TypedPropertyFromDoctrineCollectionRectorTest
|
||||
*/
|
||||
final class TypedPropertyFromDoctrineCollectionRector extends AbstractRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Doctrine\TypeAnalyzer\DoctrineCollectionTypeAnalyzer
|
||||
*/
|
||||
private $doctrineCollectionTypeAnalyzer;
|
||||
public function __construct(DoctrineCollectionTypeAnalyzer $doctrineCollectionTypeAnalyzer)
|
||||
{
|
||||
$this->doctrineCollectionTypeAnalyzer = $doctrineCollectionTypeAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Add typed property based on Doctrine collection', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\TrainingTerm;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class DoctrineCollection
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\TrainingTerm", mappedBy="training")
|
||||
* @var TrainingTerm[]|Collection
|
||||
*/
|
||||
private $trainingTerms;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\TrainingTerm;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class DoctrineCollection
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\TrainingTerm", mappedBy="training")
|
||||
* @var TrainingTerm[]|Collection
|
||||
*/
|
||||
private \Doctrine\Common\Collections\Collection $trainingTerms;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Property::class];
|
||||
}
|
||||
/**
|
||||
* @param Property $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($node->type !== null) {
|
||||
return null;
|
||||
}
|
||||
$propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
|
||||
if (!$propertyPhpDocInfo instanceof PhpDocInfo) {
|
||||
return null;
|
||||
}
|
||||
$varTagValueNode = $propertyPhpDocInfo->getVarTagValueNode();
|
||||
if (!$varTagValueNode instanceof VarTagValueNode) {
|
||||
return null;
|
||||
}
|
||||
$varTagType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($varTagValueNode->type, $node);
|
||||
if (!$this->doctrineCollectionTypeAnalyzer->detect($varTagType)) {
|
||||
return null;
|
||||
}
|
||||
$node->type = new FullyQualified('Doctrine\\Common\\Collections\\Collection');
|
||||
return $node;
|
||||
}
|
||||
public function provideMinPhpVersion() : int
|
||||
{
|
||||
return PhpVersion::PHP_74;
|
||||
}
|
||||
}
|
49
vendor/rector/rector-doctrine/src/TypeAnalyzer/DoctrineCollectionTypeAnalyzer.php
vendored
Normal file
49
vendor/rector/rector-doctrine/src/TypeAnalyzer/DoctrineCollectionTypeAnalyzer.php
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\TypeAnalyzer;
|
||||
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeWithClassName;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
|
||||
/**
|
||||
* @todo replaces core one
|
||||
* @see \Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer
|
||||
*/
|
||||
final class DoctrineCollectionTypeAnalyzer
|
||||
{
|
||||
public function detect(Type $type) : bool
|
||||
{
|
||||
if (!$type instanceof UnionType) {
|
||||
return \false;
|
||||
}
|
||||
$arrayType = null;
|
||||
$hasDoctrineCollectionType = \false;
|
||||
foreach ($type->getTypes() as $unionedType) {
|
||||
if ($this->isCollectionObjectType($unionedType)) {
|
||||
$hasDoctrineCollectionType = \true;
|
||||
}
|
||||
if ($unionedType instanceof ArrayType) {
|
||||
$arrayType = $unionedType;
|
||||
}
|
||||
}
|
||||
if (!$hasDoctrineCollectionType) {
|
||||
return \false;
|
||||
}
|
||||
return $arrayType !== null;
|
||||
}
|
||||
private function isCollectionObjectType(Type $type) : bool
|
||||
{
|
||||
if (!$type instanceof TypeWithClassName) {
|
||||
return \false;
|
||||
}
|
||||
if ($type instanceof ShortenedObjectType) {
|
||||
$className = $type->getFullyQualifiedName();
|
||||
} else {
|
||||
$className = $type->getClassName();
|
||||
}
|
||||
return $className === 'Doctrine\\Common\\Collections\\Collection';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user