mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 11:50:51 +00:00
Updated Rector to commit 863fee39147717a4f85c42eacaec28fe6971ac52
863fee3914
[PHPStanStaticTypeMapper] Handle Nullable Type on UnionType on UnionTypeMapper when possible (#3173)
This commit is contained in:
parent
4bc9094047
commit
f63eee898e
|
@ -128,7 +128,7 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
return $arrayNode;
|
||||
}
|
||||
if ($this->boolUnionTypeAnalyzer->isNullableBoolUnionType($type) && !$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
|
||||
return new NullableType(new Name('bool'));
|
||||
return $this->resolveNullableType(new NullableType(new Name('bool')));
|
||||
}
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES) && $this->isFalseBoolUnion($type)) {
|
||||
// return new Bool
|
||||
|
@ -142,6 +142,13 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
}
|
||||
return $this->mapNullabledType($nullabledType, $typeKind);
|
||||
}
|
||||
private function resolveNullableType(NullableType $nullableType) : ?NullableType
|
||||
{
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::NULLABLE_TYPE)) {
|
||||
return null;
|
||||
}
|
||||
return $nullableType;
|
||||
}
|
||||
/**
|
||||
* @param TypeKind::* $typeKind
|
||||
*/
|
||||
|
@ -160,7 +167,7 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
}
|
||||
/** @var Name $nullabledTypeNode */
|
||||
if (!$this->nodeNameResolver->isNames($nullabledTypeNode, ['false', 'mixed'])) {
|
||||
return new NullableType($nullabledTypeNode);
|
||||
return $this->resolveNullableType(new NullableType($nullabledTypeNode));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -186,10 +193,31 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
}
|
||||
$type = $unionTypeAnalysis->hasIterable() ? 'iterable' : 'array';
|
||||
if ($unionTypeAnalysis->isNullableType()) {
|
||||
return new NullableType($type);
|
||||
return $this->resolveNullableType(new NullableType($type));
|
||||
}
|
||||
return new Name($type);
|
||||
}
|
||||
/**
|
||||
* @return PhpParserUnionType|\PhpParser\Node\NullableType|null
|
||||
*/
|
||||
private function resolveTypeWithNullablePHPParserUnionType(PhpParserUnionType $phpParserUnionType)
|
||||
{
|
||||
if (\count($phpParserUnionType->types) === 2) {
|
||||
$phpParserUnionType->types = \array_values($phpParserUnionType->types);
|
||||
$firstType = $phpParserUnionType->types[0];
|
||||
$secondType = $phpParserUnionType->types[1];
|
||||
if ($firstType instanceof Name && $firstType->toString() === 'null' && !$secondType instanceof PHPParserNodeIntersectionType) {
|
||||
return $this->resolveNullableType(new NullableType($secondType));
|
||||
}
|
||||
if ($secondType instanceof Name && $secondType->toString() === 'null' && !$firstType instanceof PHPParserNodeIntersectionType) {
|
||||
return $this->resolveNullableType(new NullableType($firstType));
|
||||
}
|
||||
}
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
|
||||
return null;
|
||||
}
|
||||
return $phpParserUnionType;
|
||||
}
|
||||
private function matchTypeForNullableUnionType(UnionType $unionType) : ?Type
|
||||
{
|
||||
if (\count($unionType->getTypes()) !== 2) {
|
||||
|
@ -218,6 +246,9 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
private function matchTypeForUnionedObjectTypes(UnionType $unionType, string $typeKind) : ?Node
|
||||
{
|
||||
$phpParserUnionType = $this->matchPhpParserUnionType($unionType, $typeKind);
|
||||
if ($phpParserUnionType instanceof NullableType) {
|
||||
return $phpParserUnionType;
|
||||
}
|
||||
if ($phpParserUnionType !== null) {
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
|
||||
// maybe all one type?
|
||||
|
@ -256,7 +287,7 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
if ($compatibleObjectType instanceof UnionType) {
|
||||
$type = $this->matchTypeForNullableUnionType($compatibleObjectType);
|
||||
if ($type instanceof ObjectType) {
|
||||
return new NullableType(new FullyQualified($type->getClassName()));
|
||||
return $this->resolveNullableType(new NullableType(new FullyQualified($type->getClassName())));
|
||||
}
|
||||
}
|
||||
if (!$compatibleObjectType instanceof ObjectType) {
|
||||
|
@ -266,12 +297,10 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
}
|
||||
/**
|
||||
* @param TypeKind::* $typeKind
|
||||
* @return PhpParserUnionType|\PhpParser\Node\NullableType|null
|
||||
*/
|
||||
private function matchPhpParserUnionType(UnionType $unionType, string $typeKind) : ?PhpParserUnionType
|
||||
private function matchPhpParserUnionType(UnionType $unionType, string $typeKind)
|
||||
{
|
||||
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
|
||||
return null;
|
||||
}
|
||||
$phpParserUnionedTypes = [];
|
||||
foreach ($unionType->getTypes() as $unionedType) {
|
||||
// void type and mixed type are not allowed in union
|
||||
|
@ -295,10 +324,11 @@ final class UnionTypeMapper implements TypeMapperInterface
|
|||
}
|
||||
/** @var Identifier[]|Name[] $phpParserUnionedTypes */
|
||||
$phpParserUnionedTypes = \array_unique($phpParserUnionedTypes);
|
||||
if (\count($phpParserUnionedTypes) < 2) {
|
||||
$countPhpParserUnionedTypes = \count($phpParserUnionedTypes);
|
||||
if ($countPhpParserUnionedTypes < 2) {
|
||||
return null;
|
||||
}
|
||||
return new PhpParserUnionType($phpParserUnionedTypes);
|
||||
return $this->resolveTypeWithNullablePHPParserUnionType(new PhpParserUnionType($phpParserUnionedTypes));
|
||||
}
|
||||
/**
|
||||
* @return \PHPStan\Type\UnionType|\PHPStan\Type\TypeWithClassName|null
|
||||
|
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'bbd9d4fa2c6811c9c68984549d2c0dfb68232219';
|
||||
public const PACKAGE_VERSION = '863fee39147717a4f85c42eacaec28fe6971ac52';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-12-08 11:11:58';
|
||||
public const RELEASE_DATE = '2022-12-09 12:19:22';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
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 ComposerAutoloaderInit0a75c686bee35d8a18937bc2ee382502::getLoader();
|
||||
return ComposerAutoloaderInit64d4510e3f7ad68baffa6c1c4009d195::getLoader();
|
||||
|
|
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 ComposerAutoloaderInit0a75c686bee35d8a18937bc2ee382502
|
||||
class ComposerAutoloaderInit64d4510e3f7ad68baffa6c1c4009d195
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit0a75c686bee35d8a18937bc2ee382502
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit0a75c686bee35d8a18937bc2ee382502', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit64d4510e3f7ad68baffa6c1c4009d195', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit0a75c686bee35d8a18937bc2ee382502', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit64d4510e3f7ad68baffa6c1c4009d195', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit0a75c686bee35d8a18937bc2ee382502::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit64d4510e3f7ad68baffa6c1c4009d195::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit0a75c686bee35d8a18937bc2ee382502::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit64d4510e3f7ad68baffa6c1c4009d195::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire0a75c686bee35d8a18937bc2ee382502($fileIdentifier, $file);
|
||||
composerRequire64d4510e3f7ad68baffa6c1c4009d195($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit0a75c686bee35d8a18937bc2ee382502
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire0a75c686bee35d8a18937bc2ee382502($fileIdentifier, $file)
|
||||
function composerRequire64d4510e3f7ad68baffa6c1c4009d195($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit0a75c686bee35d8a18937bc2ee382502
|
||||
class ComposerStaticInit64d4510e3f7ad68baffa6c1c4009d195
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3025,9 +3025,9 @@ class ComposerStaticInit0a75c686bee35d8a18937bc2ee382502
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0a75c686bee35d8a18937bc2ee382502::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit0a75c686bee35d8a18937bc2ee382502::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit0a75c686bee35d8a18937bc2ee382502::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit64d4510e3f7ad68baffa6c1c4009d195::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit64d4510e3f7ad68baffa6c1c4009d195::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit64d4510e3f7ad68baffa6c1c4009d195::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
|
@ -1780,12 +1780,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "bf394eec1e4612ceae5b6ee3c574e37f81f422b7"
|
||||
"reference": "61634310cf2be58e39647a51b0fe727b38d7874b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/bf394eec1e4612ceae5b6ee3c574e37f81f422b7",
|
||||
"reference": "bf394eec1e4612ceae5b6ee3c574e37f81f422b7",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/61634310cf2be58e39647a51b0fe727b38d7874b",
|
||||
"reference": "61634310cf2be58e39647a51b0fe727b38d7874b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1811,7 +1811,7 @@
|
|||
"symplify\/rule-doc-generator": "^11.1",
|
||||
"symplify\/vendor-patches": "^11.1"
|
||||
},
|
||||
"time": "2022-11-14T14:41:41+00:00",
|
||||
"time": "2022-12-09T08:25:11+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 bf394ee'), '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 b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), '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 7ea9a12'), '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 f77e493'));
|
||||
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 6163431'), '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 b1ca6d7'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), '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 7ea9a12'), '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 f77e493'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 30 Rules Overview
|
||||
# 23 Rules Overview
|
||||
|
||||
## AddEntityIdByConditionRector
|
||||
|
||||
|
@ -9,11 +9,15 @@ Add entity id with annotations when meets condition
|
|||
- 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, [Rector\Doctrine\Rector\Class_\AddEntityIdByConditionRector::DETECTED_TRAITS: ['Knp\DoctrineBehaviors\Model\Translatable\Translation', 'Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait']]);
|
||||
$rectorConfig->ruleWithConfiguration(AddEntityIdByConditionRector::class, [AddEntityIdByConditionRector::DETECTED_TRAITS => ['Knp\DoctrineBehaviors\Model\Translatable\Translation', 'Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait']]);
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -42,59 +46,6 @@ return static function (RectorConfig $rectorConfig): void {
|
|||
|
||||
<br>
|
||||
|
||||
## BlameableBehaviorRector
|
||||
|
||||
Change Blameable from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\BlameableBehaviorRector`](../src/Rector/Class_/BlameableBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
-use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
|
||||
+use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
-class SomeClass
|
||||
+class SomeClass implements BlameableInterface
|
||||
{
|
||||
- /**
|
||||
- * @Gedmo\Blameable(on="create")
|
||||
- */
|
||||
- private $createdBy;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\Blameable(on="update")
|
||||
- */
|
||||
- private $updatedBy;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\Blameable(on="change", field={"title", "body"})
|
||||
- */
|
||||
- private $contentChangedBy;
|
||||
-
|
||||
- public function getCreatedBy()
|
||||
- {
|
||||
- return $this->createdBy;
|
||||
- }
|
||||
-
|
||||
- public function getUpdatedBy()
|
||||
- {
|
||||
- return $this->updatedBy;
|
||||
- }
|
||||
-
|
||||
- public function getContentChangedBy()
|
||||
- {
|
||||
- return $this->contentChangedBy;
|
||||
- }
|
||||
+ use BlameableTrait;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## ChangeBigIntEntityPropertyToIntTypeRector
|
||||
|
||||
Change database type "bigint" for @var/type declaration to string
|
||||
|
@ -207,6 +158,8 @@ Change default value types to match Doctrine annotation type
|
|||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## DoctrineTargetEntityStringToClassConstantRector
|
||||
|
||||
Convert targetEntities defined as String to <class>::class Constants in Doctrine Entities.
|
||||
|
@ -214,8 +167,8 @@ Convert targetEntities defined as String to <class>::class Constants in Doctrine
|
|||
- class: [`Rector\Doctrine\Rector\Property\DoctrineTargetEntityStringToClassConstantRector`](../src/Rector/Property/DoctrineTargetEntityStringToClassConstantRector.php)
|
||||
|
||||
```diff
|
||||
final class SomeClass
|
||||
{
|
||||
final class SomeClass
|
||||
{
|
||||
/**
|
||||
- * @ORM\OneToMany(targetEntity="AnotherClass")
|
||||
+ * @ORM\OneToMany(targetEntity=\MyNamespace\Source\AnotherClass::class)
|
||||
|
@ -239,11 +192,15 @@ Replaces doctrine alias with class.
|
|||
- class: [`Rector\Doctrine\Rector\MethodCall\EntityAliasToClassConstantReferenceRector`](../src/Rector/MethodCall/EntityAliasToClassConstantReferenceRector.php)
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Doctrine\Rector\MethodCall\EntityAliasToClassConstantReferenceRector;
|
||||
|
||||
return static function (RectorConfig $rectorConfig): void {
|
||||
$rectorConfig->ruleWithConfiguration(EntityAliasToClassConstantReferenceRector::class, [Rector\Doctrine\Rector\MethodCall\EntityAliasToClassConstantReferenceRector::ALIASES_TO_NAMESPACES: ['App' => 'App\Entity']]);
|
||||
$rectorConfig->ruleWithConfiguration(EntityAliasToClassConstantReferenceRector::class, [EntityAliasToClassConstantReferenceRector::ALIASES_TO_NAMESPACES => ['App' => 'App\Entity']]);
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -311,37 +268,6 @@ Initialize collection property in Entity constructor
|
|||
|
||||
<br>
|
||||
|
||||
## LoggableBehaviorRector
|
||||
|
||||
Change Loggable from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\LoggableBehaviorRector`](../src/Rector/Class_/LoggableBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
-use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
+use Knp\DoctrineBehaviors\Model\Loggable\LoggableTrait;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\LoggableInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
- * @Gedmo\Loggable
|
||||
*/
|
||||
-class SomeClass
|
||||
+class SomeClass implements LoggableInterface
|
||||
{
|
||||
+ use LoggableTrait;
|
||||
+
|
||||
/**
|
||||
- * @Gedmo\Versioned
|
||||
* @ORM\Column(name="title", type="string", length=8)
|
||||
*/
|
||||
private $title;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## MakeEntityDateTimePropertyDateTimeInterfaceRector
|
||||
|
||||
Make maker bundle generate DateTime property accept DateTimeInterface too
|
||||
|
@ -387,6 +313,7 @@ Make nullability in setter class method with respect to property
|
|||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AnotherEntity")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $anotherEntity;
|
||||
|
||||
|
@ -619,243 +546,6 @@ Change ServiceEntityRepository to dependency injection, with repository property
|
|||
|
||||
<br>
|
||||
|
||||
## SluggableBehaviorRector
|
||||
|
||||
Change Sluggable from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\SluggableBehaviorRector`](../src/Rector/Class_/SluggableBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
+use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
|
||||
|
||||
-class SomeClass
|
||||
+class SomeClass implements SluggableInterface
|
||||
{
|
||||
+ use SluggableTrait;
|
||||
+
|
||||
/**
|
||||
- * @Gedmo\Slug(fields={"name"})
|
||||
+ * @return string[]
|
||||
*/
|
||||
- private $slug;
|
||||
-
|
||||
- public function getSlug(): ?string
|
||||
+ public function getSluggableFields(): array
|
||||
{
|
||||
- return $this->slug;
|
||||
- }
|
||||
-
|
||||
- public function setSlug(?string $slug): void
|
||||
- {
|
||||
- $this->slug = $slug;
|
||||
+ return ['name'];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## SoftDeletableBehaviorRector
|
||||
|
||||
Change SoftDeletable from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\SoftDeletableBehaviorRector`](../src/Rector/Class_/SoftDeletableBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
-use Gedmo\Mapping\Annotation as Gedmo;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
|
||||
+use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
|
||||
|
||||
-/**
|
||||
- * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
|
||||
- */
|
||||
-class SomeClass
|
||||
+class SomeClass implements SoftDeletableInterface
|
||||
{
|
||||
- /**
|
||||
- * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
|
||||
- */
|
||||
- private $deletedAt;
|
||||
-
|
||||
- public function getDeletedAt()
|
||||
- {
|
||||
- return $this->deletedAt;
|
||||
- }
|
||||
-
|
||||
- public function setDeletedAt($deletedAt)
|
||||
- {
|
||||
- $this->deletedAt = $deletedAt;
|
||||
- }
|
||||
+ use SoftDeletableTrait;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## TimestampableBehaviorRector
|
||||
|
||||
Change Timestampable from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\TimestampableBehaviorRector`](../src/Rector/Class_/TimestampableBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
-use Gedmo\Timestampable\Traits\TimestampableEntity;
|
||||
+use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
|
||||
|
||||
-class SomeClass
|
||||
+class SomeClass implements TimestampableInterface
|
||||
{
|
||||
- use TimestampableEntity;
|
||||
+ use TimestampableTrait;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## TranslationBehaviorRector
|
||||
|
||||
Change Translation from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\TranslationBehaviorRector`](../src/Rector/Class_/TranslationBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
-use Gedmo\Mapping\Annotation as Gedmo;
|
||||
-use Doctrine\ORM\Mapping as ORM;
|
||||
-use Gedmo\Translatable\Translatable;
|
||||
+use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
|
||||
|
||||
-/**
|
||||
- * @ORM\Table
|
||||
- */
|
||||
-class Article implements Translatable
|
||||
+class SomeClass implements TranslatableInterface
|
||||
{
|
||||
+ use TranslatableTrait;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\TranslationInterface;
|
||||
+use Knp\DoctrineBehaviors\Model\Translatable\TranslationTrait;
|
||||
+
|
||||
+class SomeClassTranslation implements TranslationInterface
|
||||
+{
|
||||
+ use TranslationTrait;
|
||||
+
|
||||
/**
|
||||
- * @Gedmo\Translatable
|
||||
* @ORM\Column(length=128)
|
||||
*/
|
||||
private $title;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\Locale
|
||||
- */
|
||||
- private $locale;
|
||||
-
|
||||
- public function setTitle($title)
|
||||
- {
|
||||
- $this->title = $title;
|
||||
- }
|
||||
-
|
||||
- public function getTitle()
|
||||
- {
|
||||
- return $this->title;
|
||||
- }
|
||||
-
|
||||
- public function setTranslatableLocale($locale)
|
||||
- {
|
||||
- $this->locale = $locale;
|
||||
- }
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## TreeBehaviorRector
|
||||
|
||||
Change Tree from gedmo/doctrine-extensions to knplabs/doctrine-behaviors
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Class_\TreeBehaviorRector`](../src/Rector/Class_/TreeBehaviorRector.php)
|
||||
|
||||
```diff
|
||||
-use Doctrine\Common\Collections\Collection;
|
||||
-use Gedmo\Mapping\Annotation as Gedmo;
|
||||
+use Knp\DoctrineBehaviors\Contract\Entity\TreeNodeInterface;
|
||||
+use Knp\DoctrineBehaviors\Model\Tree\TreeNodeTrait;
|
||||
|
||||
-/**
|
||||
- * @Gedmo\Tree(type="nested")
|
||||
- */
|
||||
-class SomeClass
|
||||
+class SomeClass implements TreeNodeInterface
|
||||
{
|
||||
- /**
|
||||
- * @Gedmo\TreeLeft
|
||||
- * @ORM\Column(name="lft", type="integer")
|
||||
- * @var int
|
||||
- */
|
||||
- private $lft;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\TreeRight
|
||||
- * @ORM\Column(name="rgt", type="integer")
|
||||
- * @var int
|
||||
- */
|
||||
- private $rgt;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\TreeLevel
|
||||
- * @ORM\Column(name="lvl", type="integer")
|
||||
- * @var int
|
||||
- */
|
||||
- private $lvl;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\TreeRoot
|
||||
- * @ORM\ManyToOne(targetEntity="Category")
|
||||
- * @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE")
|
||||
- * @var Category
|
||||
- */
|
||||
- private $root;
|
||||
-
|
||||
- /**
|
||||
- * @Gedmo\TreeParent
|
||||
- * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
|
||||
- * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
|
||||
- * @var Category
|
||||
- */
|
||||
- private $parent;
|
||||
-
|
||||
- /**
|
||||
- * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
|
||||
- * @var Category[]|Collection
|
||||
- */
|
||||
- private $children;
|
||||
-
|
||||
- public function getRoot(): self
|
||||
- {
|
||||
- return $this->root;
|
||||
- }
|
||||
-
|
||||
- public function setParent(self $category): void
|
||||
- {
|
||||
- $this->parent = $category;
|
||||
- }
|
||||
-
|
||||
- public function getParent(): self
|
||||
- {
|
||||
- return $this->parent;
|
||||
- }
|
||||
+ use TreeNodeTrait;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## TypedPropertyFromColumnTypeRector
|
||||
|
||||
Complete `@var` annotations or types based on @ORM\Column
|
||||
|
@ -877,22 +567,27 @@ Complete `@var` annotations or types based on @ORM\Column
|
|||
|
||||
<br>
|
||||
|
||||
## TypedPropertyFromToOneRelationTypeRector
|
||||
## TypedPropertyFromDoctrineCollectionRector
|
||||
|
||||
Complete `@var` annotations or types based on @ORM\*toOne annotations or attributes
|
||||
Add typed property based on Doctrine collection
|
||||
|
||||
- class: [`Rector\Doctrine\Rector\Property\TypedPropertyFromToOneRelationTypeRector`](../src/Rector/Property/TypedPropertyFromToOneRelationTypeRector.php)
|
||||
- class: [`Rector\Doctrine\Rector\Property\TypedPropertyFromDoctrineCollectionRector`](../src/Rector/Property/TypedPropertyFromDoctrineCollectionRector.php)
|
||||
|
||||
```diff
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use App\Entity\TrainingTerm;
|
||||
|
||||
class SimpleColumn
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class DoctrineCollection
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Company\Entity\Company")
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\TrainingTerm", mappedBy="training")
|
||||
* @var TrainingTerm[]|Collection
|
||||
*/
|
||||
- private $company;
|
||||
+ private ?\App\Company\Entity\Company $company = null;
|
||||
- private $trainingTerms;
|
||||
+ private \Doctrine\Common\Collections\Collection $trainingTerms;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user