mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 11:50:51 +00:00
remove runnable interface, to lower complexity (#5829)
This commit is contained in:
parent
721f619a1d
commit
0acc05cc6e
|
@ -44,7 +44,6 @@
|
|||
"symfony/cache": "^4.4.8|^5.1",
|
||||
"symfony/console": "^4.4.8|^5.1",
|
||||
"symfony/dependency-injection": "^5.1",
|
||||
"symfony/expression-language": "^4.4.8|^5.1",
|
||||
"symfony/finder": "^4.4.8|^5.1",
|
||||
"symfony/http-kernel": "^4.4.8|^5.1",
|
||||
"symfony/process": "^4.4.8|^5.1",
|
||||
|
|
|
@ -8,9 +8,6 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
|||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
// @todo this should be removed
|
||||
$containerConfigurator->import(__DIR__ . '/../packages/*/config/config.php');
|
||||
|
||||
$containerConfigurator->import(__DIR__ . '/../rules/*/config/config.php');
|
||||
$containerConfigurator->import(__DIR__ . '/services.php');
|
||||
$containerConfigurator->import(__DIR__ . '/services-rules.php');
|
||||
$containerConfigurator->import(__DIR__ . '/parameters.php');
|
||||
|
|
|
@ -83,7 +83,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
__DIR__ . '/../packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php',
|
||||
__DIR__ . '/../packages/*/{ValueObject,Contract,Exception}',
|
||||
__DIR__ . '/../packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php',
|
||||
__DIR__ . '/../packages/Testing/PHPUnit/Runnable/NodeVisitor',
|
||||
__DIR__ . '/../packages/Testing/PHPUnit',
|
||||
]);
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
# add uuid id property
|
||||
$services->set(AddUuidToEntityWhereMissingRector::class);
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(AlwaysInitializeUuidInEntityRector::class);
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
# add relations uuid properties
|
||||
$services->set(AddUuidMirrorForRelationPropertyRector::class);
|
||||
};
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Doctrine\Rector\ClassMethod\ChangeGetIdTypeToUuidRector;
|
||||
use Rector\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector;
|
||||
use Rector\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector;
|
||||
use Rector\Doctrine\Rector\Property\RemoveTemporaryUuidColumnPropertyRector;
|
||||
use Rector\Doctrine\Rector\Property\RemoveTemporaryUuidRelationPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
# properties
|
||||
$services->set(AddUuidAnnotationsToIdPropertyRector::class);
|
||||
|
||||
$services->set(RemoveTemporaryUuidColumnPropertyRector::class);
|
||||
|
||||
$services->set(RemoveTemporaryUuidRelationPropertyRector::class);
|
||||
|
||||
# methods
|
||||
$services->set(ChangeGetIdTypeToUuidRector::class);
|
||||
|
||||
$services->set(ChangeSetIdTypeToUuidRector::class);
|
||||
};
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector;
|
||||
use Rector\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector;
|
||||
use Rector\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector;
|
||||
use Rector\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(ChangeSetIdToUuidValueRector::class);
|
||||
|
||||
$services->set(ChangeGetUuidMethodCallToGetIdRector::class);
|
||||
|
||||
$services->set(ChangeReturnTypeOfClassMethodWithGetIdRector::class);
|
||||
|
||||
$services->set(ChangeIdenticalUuidToEqualsMethodCallRector::class);
|
||||
|
||||
# add Uuid type declarations
|
||||
$services->set(AddMethodCallBasedStrictParamTypeRector::class);
|
||||
|
||||
$services->set(AddArrayReturnDocTypeRector::class);
|
||||
};
|
|
@ -148,31 +148,6 @@ final class SetList implements SetListInterface
|
|||
*/
|
||||
public const DOCTRINE_GEDMO_TO_KNPLABS = __DIR__ . '/../../../config/set/doctrine-gedmo-to-knplabs.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const DOCTRINE_ID_TO_UUID_STEP_1 = __DIR__ . '/../../../config/set/doctrine-id-to-uuid-step-1.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const DOCTRINE_ID_TO_UUID_STEP_2 = __DIR__ . '/../../../config/set/doctrine-id-to-uuid-step-2.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const DOCTRINE_ID_TO_UUID_STEP_3 = __DIR__ . '/../../../config/set/doctrine-id-to-uuid-step-3.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const DOCTRINE_ID_TO_UUID_STEP_4 = __DIR__ . '/../../../config/set/doctrine-id-to-uuid-step-4.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const DOCTRINE_ID_TO_UUID_STEP_5 = __DIR__ . '/../../../config/set/doctrine-id-to-uuid-step-5.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Testing\Contract;
|
||||
|
||||
interface RunnableInterface
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function run();
|
||||
}
|
|
@ -22,7 +22,6 @@ use Rector\Core\ValueObject\StaticNonPhpFileSuffixes;
|
|||
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
|
||||
use Rector\Testing\Application\EnabledRectorClassProvider;
|
||||
use Rector\Testing\Configuration\AllRectorConfigFactory;
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
use Rector\Testing\Guard\FixtureGuard;
|
||||
use Rector\Testing\PHPUnit\Behavior\MovingFilesTrait;
|
||||
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
||||
|
@ -82,11 +81,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
|
|||
*/
|
||||
private static $isInitialized = false;
|
||||
|
||||
/**
|
||||
* @var RunnableRectorFactory
|
||||
*/
|
||||
private static $runnableRectorFactory;
|
||||
|
||||
/**
|
||||
* @var RectorConfigsResolver
|
||||
*/
|
||||
|
@ -176,8 +170,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
|
|||
|
||||
$this->doTestFileMatchesExpectedContent($inputFileInfo, $expectedFileInfo, $fixtureFileInfo, $extraFileInfos);
|
||||
$this->originalTempFileInfo = $inputFileInfo;
|
||||
|
||||
$this->processRunnableTest($inputFileInfo, $expectedFileInfo);
|
||||
}
|
||||
|
||||
protected function doTestExtraFile(string $expectedExtraFileName, string $expectedExtraContentFilePath): void
|
||||
|
@ -221,18 +213,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
|
|||
return sys_get_temp_dir() . '/_temp_fixture_easy_testing';
|
||||
}
|
||||
|
||||
protected function assertOriginalAndFixedFileResultEquals(
|
||||
SmartFileInfo $originalFileInfo,
|
||||
SmartFileInfo $expectedFileInfo
|
||||
): void {
|
||||
$inputRunnable = self::$runnableRectorFactory->createRunnableClass($originalFileInfo);
|
||||
$expectedRunnable = self::$runnableRectorFactory->createRunnableClass($expectedFileInfo);
|
||||
|
||||
$inputResult = $inputRunnable->run();
|
||||
$expectedResult = $expectedRunnable->run();
|
||||
$this->assertSame($expectedResult, $inputResult);
|
||||
}
|
||||
|
||||
private function createRectorRepositoryContainer(): void
|
||||
{
|
||||
if (self::$allRectorContainer === null) {
|
||||
|
@ -324,24 +304,9 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
|
|||
return;
|
||||
}
|
||||
|
||||
self::$runnableRectorFactory = new RunnableRectorFactory();
|
||||
self::$smartFileSystem = new SmartFileSystem();
|
||||
self::$fixtureGuard = new FixtureGuard();
|
||||
self::$rectorConfigsResolver = new RectorConfigsResolver();
|
||||
self::$isInitialized = true;
|
||||
}
|
||||
|
||||
private function processRunnableTest(SmartFileInfo $inputFileInfo, SmartFileInfo $expectedFileInfo): void
|
||||
{
|
||||
// runnable?
|
||||
if (! file_exists($inputFileInfo->getPathname())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! Strings::contains($inputFileInfo->getContents(), RunnableInterface::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertOriginalAndFixedFileResultEquals($inputFileInfo, $expectedFileInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Testing\PHPUnit\Runnable;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\Parser;
|
||||
use PhpParser\ParserFactory;
|
||||
use PhpParser\PrettyPrinter\Standard;
|
||||
use Rector\Testing\PHPUnit\Runnable\NodeVisitor\ClassLikeNameCollectingNodeVisitor;
|
||||
use Rector\Testing\PHPUnit\Runnable\NodeVisitor\PrefixingClassLikeNamesNodeVisitor;
|
||||
|
||||
final class ClassLikeNamesSuffixer
|
||||
{
|
||||
/**
|
||||
* @var Parser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* @var Standard
|
||||
*/
|
||||
private $standard;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
|
||||
$this->standard = new Standard();
|
||||
}
|
||||
|
||||
public function suffixContent(string $content, string $classSuffix): string
|
||||
{
|
||||
/** @var Node[] $nodes */
|
||||
$nodes = $this->parser->parse($content);
|
||||
|
||||
// collect all class, trait, interface local names, e.g. class <name>, interface <name>
|
||||
$classLikeNameCollectingNodeVisitor = new ClassLikeNameCollectingNodeVisitor();
|
||||
$nodeTraverser = new NodeTraverser();
|
||||
$nodeTraverser->addVisitor($classLikeNameCollectingNodeVisitor);
|
||||
$nodeTraverser->traverse($nodes);
|
||||
|
||||
$classLikeNames = $classLikeNameCollectingNodeVisitor->getClassLikeNames();
|
||||
|
||||
// replace those class names in code
|
||||
$nodeTraverser = new NodeTraverser();
|
||||
$nodeTraverser->addVisitor(new PrefixingClassLikeNamesNodeVisitor($classLikeNames, $classSuffix));
|
||||
|
||||
$nodes = $nodeTraverser->traverse($nodes);
|
||||
|
||||
return $this->standard->prettyPrintFile($nodes);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Testing\PHPUnit\Runnable\NodeVisitor;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
final class ClassLikeNameCollectingNodeVisitor extends NodeVisitorAbstract
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $classLikeNames = [];
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getClassLikeNames(): array
|
||||
{
|
||||
return $this->classLikeNames;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
if (! $node instanceof ClassLike) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($node->name === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->classLikeNames[] = $node->name->toString();
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Testing\PHPUnit\Runnable\NodeVisitor;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
|
||||
/**
|
||||
* Very dummy, use carefully and extend if needed
|
||||
*/
|
||||
final class PrefixingClassLikeNamesNodeVisitor extends NodeVisitorAbstract
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $suffix;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $classLikeNames = [];
|
||||
|
||||
/**
|
||||
* @param string[] $classLikeNames
|
||||
*/
|
||||
public function __construct(array $classLikeNames, string $suffix)
|
||||
{
|
||||
$this->classLikeNames = $classLikeNames;
|
||||
$this->suffix = $suffix;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node): ?Node
|
||||
{
|
||||
if ($node instanceof ClassLike) {
|
||||
return $this->refactorClassLike($node);
|
||||
}
|
||||
|
||||
if ($node instanceof New_) {
|
||||
return $this->refactorNew($node);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function refactorClassLike(ClassLike $classLike): ?ClassLike
|
||||
{
|
||||
if ($classLike->name === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// rename extends
|
||||
if ($classLike instanceof Class_) {
|
||||
$this->refactorClass($classLike);
|
||||
}
|
||||
|
||||
foreach ($this->classLikeNames as $classLikeName) {
|
||||
$className = $classLike->name->toString();
|
||||
if ($className !== $classLikeName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classLike->name = new Identifier($classLikeName . '_' . $this->suffix);
|
||||
return $classLike;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function refactorNew(New_ $new): ?New_
|
||||
{
|
||||
if (! $new->class instanceof Name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->classLikeNames as $classLikeName) {
|
||||
$className = $new->class->toString();
|
||||
if ($className !== $classLikeName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$new->class = new Name($classLikeName . '_' . $this->suffix);
|
||||
return $new;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function refactorClass(Class_ $class): void
|
||||
{
|
||||
if ($class->extends === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$extends = $class->extends->toString();
|
||||
|
||||
foreach ($this->classLikeNames as $classLikeName) {
|
||||
if ($extends !== $classLikeName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$class->extends = new Name($extends . '_' . $this->suffix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Testing\PHPUnit\Runnable;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\NodeFinder;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PhpParser\NodeVisitor\NameResolver;
|
||||
use PhpParser\Parser;
|
||||
use PhpParser\ParserFactory;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class RunnableClassFinder
|
||||
{
|
||||
/**
|
||||
* @var Parser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* @var NodeFinder
|
||||
*/
|
||||
private $nodeFinder;
|
||||
|
||||
public function __construct(NodeFinder $nodeFinder)
|
||||
{
|
||||
$parserFactory = new ParserFactory();
|
||||
$this->parser = $parserFactory->create(ParserFactory::PREFER_PHP7);
|
||||
$this->nodeFinder = $nodeFinder;
|
||||
}
|
||||
|
||||
public function find(string $content): string
|
||||
{
|
||||
/** @var Node[] $nodes */
|
||||
$nodes = $this->parser->parse($content);
|
||||
$this->decorateNodesWithNames($nodes);
|
||||
|
||||
$class = $this->findClassThatImplementsRunnableInterface($nodes);
|
||||
|
||||
return (string) $class->namespacedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
*/
|
||||
private function decorateNodesWithNames(array $nodes): void
|
||||
{
|
||||
$nodeTraverser = new NodeTraverser();
|
||||
$nodeTraverser->addVisitor(new NameResolver(null, [
|
||||
'preserveOriginalNames' => true,
|
||||
]));
|
||||
$nodeTraverser->traverse($nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
*/
|
||||
private function findClassThatImplementsRunnableInterface(array $nodes): Class_
|
||||
{
|
||||
$class = $this->nodeFinder->findFirst($nodes, function (Node $node): bool {
|
||||
if (! $node instanceof Class_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($node->implements as $implement) {
|
||||
if ((string) $implement !== RunnableInterface::class) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (! $class instanceof Class_) {
|
||||
throw new ShouldNotHappenException();
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Testing\PHPUnit;
|
||||
|
||||
use Nette\Utils\Random;
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\NodeFinder;
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
use Rector\Testing\PHPUnit\Runnable\ClassLikeNamesSuffixer;
|
||||
use Rector\Testing\PHPUnit\Runnable\RunnableClassFinder;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
use Symplify\SmartFileSystem\SmartFileSystem;
|
||||
|
||||
final class RunnableRectorFactory
|
||||
{
|
||||
/**
|
||||
* @var RunnableClassFinder
|
||||
*/
|
||||
private $runnableClassFinder;
|
||||
|
||||
/**
|
||||
* @var ClassLikeNamesSuffixer
|
||||
*/
|
||||
private $classLikeNamesSuffixer;
|
||||
|
||||
/**
|
||||
* @var SmartFileSystem
|
||||
*/
|
||||
private $smartFileSystem;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->runnableClassFinder = new RunnableClassFinder(new NodeFinder());
|
||||
$this->classLikeNamesSuffixer = new ClassLikeNamesSuffixer();
|
||||
$this->smartFileSystem = new SmartFileSystem();
|
||||
}
|
||||
|
||||
public function createRunnableClass(SmartFileInfo $classContentFileInfo): RunnableInterface
|
||||
{
|
||||
$temporaryPath = $this->createTemporaryPathWithPrefix($classContentFileInfo);
|
||||
|
||||
$contents = $classContentFileInfo->getContents();
|
||||
$temporaryClassSuffix = $this->getTemporaryClassSuffix();
|
||||
|
||||
$suffixedFileContent = $this->classLikeNamesSuffixer->suffixContent($contents, $temporaryClassSuffix);
|
||||
|
||||
$this->smartFileSystem->dumpFile($temporaryPath, $suffixedFileContent);
|
||||
include_once $temporaryPath;
|
||||
|
||||
$runnableFullyQualifiedClassName = $this->runnableClassFinder->find($suffixedFileContent);
|
||||
|
||||
return new $runnableFullyQualifiedClassName();
|
||||
}
|
||||
|
||||
private function createTemporaryPathWithPrefix(SmartFileInfo $smartFileInfo): string
|
||||
{
|
||||
// warning: if this hash is too short, the file can becom "identical"; took me 1 hour to find out
|
||||
$hash = Strings::substring(md5($smartFileInfo->getRealPath()), -15);
|
||||
|
||||
return sprintf(sys_get_temp_dir() . '/rector/runnable_%s_%s', $hash, $smartFileInfo->getBasename('.inc'));
|
||||
}
|
||||
|
||||
private function getTemporaryClassSuffix(): string
|
||||
{
|
||||
return Random::generate(30);
|
||||
}
|
||||
}
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\ArrayKeysAndInArrayToArrayKeyExistsRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class SomeClass implements RunnableInterface
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -23,9 +21,7 @@ class SomeClass implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\ArrayKeysAndInArrayToArrayKeyExistsRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class SomeClass implements RunnableInterface
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class ArrayListBased implements RunnableInterface
|
||||
final class ArrayListBased
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -23,9 +21,7 @@ final class ArrayListBased implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class ArrayListBased implements RunnableInterface
|
||||
final class ArrayListBased
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class CompactWithExtract implements RunnableInterface
|
||||
final class CompactWithExtract
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -22,9 +20,7 @@ final class CompactWithExtract implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class CompactWithExtract implements RunnableInterface
|
||||
final class CompactWithExtract
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class CompactWithExtractParamOverride implements RunnableInterface
|
||||
final class CompactWithExtractParamOverride
|
||||
{
|
||||
public function run($result = 100)
|
||||
{
|
||||
|
@ -22,9 +20,7 @@ final class CompactWithExtractParamOverride implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class CompactWithExtractParamOverride implements RunnableInterface
|
||||
final class CompactWithExtractParamOverride
|
||||
{
|
||||
public function run($result = 100)
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class Fixture implements RunnableInterface
|
||||
final class Fixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -21,9 +19,7 @@ final class Fixture implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\CodeQuality\Rector\FuncCall\CompactToVariablesRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class Fixture implements RunnableInterface
|
||||
final class Fixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeGetIdTypeToUuidRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\ClassMethod\ChangeGetIdTypeToUuidRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ChangeGetIdTypeToUuidRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return ChangeGetIdTypeToUuidRector::class;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeGetIdTypeToUuidRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class GetId
|
||||
{
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeGetIdTypeToUuidRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class GetId
|
||||
{
|
||||
public function getId(): \Ramsey\Uuid\UuidInterface
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ChangeReturnTypeOfClassMethodWithGetIdRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return ChangeReturnTypeOfClassMethodWithGetIdRector::class;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector\Source\Building;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function getBuildingId(): int
|
||||
{
|
||||
$building = new Building();
|
||||
|
||||
return $building->getId();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector\Source\Building;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function getBuildingId(): \Ramsey\Uuid\UuidInterface
|
||||
{
|
||||
$building = new Building();
|
||||
|
||||
return $building->getId();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector\Source;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Building
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function getId(): \Ramsey\Uuid\UuidInterface
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ChangeSetIdTypeToUuidRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return ChangeSetIdTypeToUuidRector::class;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SetId
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function setId(int $uuid): int
|
||||
{
|
||||
return $this->id = $uuid;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SetId
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function setId(\Ramsey\Uuid\UuidInterface $uuid): int
|
||||
{
|
||||
return $this->id = $uuid;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipSettedId
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function setId(UuidInterface $uuid): int
|
||||
{
|
||||
return $this->id = $uuid;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class AddUuidMirrorForRelationPropertyRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return AddUuidMirrorForRelationPropertyRector::class;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipAlreadyAdded
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\YetAnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $amenity;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\YetAnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=true, referencedColumnName="uuid")
|
||||
*/
|
||||
private $amenityUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class YetAnotherEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipOneToOne
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\EntityOneToOne", cascade={"persist", "merge"}, mappedBy="skip")
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $amenity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class EntityOneToOne
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
|
||||
private $skip;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="wohoo")
|
||||
*/
|
||||
class SkipTooManyWithoutTargetEntityUuid
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\FooEntityWithoutUuid", cascade={"persist", "merge"})
|
||||
*/
|
||||
private $amenity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FooEntityWithoutUuid
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="wohoo")
|
||||
*/
|
||||
class ManyToManyWithExtraName
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\BarEntity")
|
||||
* @ORM\JoinColumn(name="role_id", referencedColumnName="id", nullable=false)
|
||||
* @Serializer\Type("Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\BarEntity")
|
||||
*/
|
||||
private $itemRole;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class BarEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="wohoo")
|
||||
*/
|
||||
class ManyToManyWithExtraName
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\BarEntity")
|
||||
* @ORM\JoinColumn(name="role_id", referencedColumnName="id", nullable=false)
|
||||
* @Serializer\Type("Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\BarEntity")
|
||||
*/
|
||||
private $itemRole;
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\BarEntity")
|
||||
* @Serializer\Type("Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\BarEntity")
|
||||
* @ORM\JoinColumn(referencedColumnName="uuid", nullable=true)
|
||||
*/
|
||||
private $itemRoleUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class BarEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="wohoo")
|
||||
*/
|
||||
class ToMany
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\FooEntity", cascade={"persist", "merge"})
|
||||
*/
|
||||
private $amenity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FooEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="wohoo")
|
||||
*/
|
||||
class ToMany
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\FooEntity", cascade={"persist", "merge"})
|
||||
*/
|
||||
private $amenity;
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\FooEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinTable(name="tomany_fooentity_uuid", joinColumns={
|
||||
* @ORM\JoinColumn(referencedColumnName="uuid")
|
||||
* }, inverseJoinColumns={
|
||||
* @ORM\JoinColumn(referencedColumnName="uuid")
|
||||
* })
|
||||
*/
|
||||
private $amenityUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class FooEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
|
||||
/**
|
||||
* @EntitY
|
||||
*/
|
||||
class SomeEntity
|
||||
{
|
||||
/**
|
||||
* @Orm\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\AnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $amenity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Orm\Entity
|
||||
*/
|
||||
class AnotherEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
|
||||
/**
|
||||
* @EntitY
|
||||
*/
|
||||
class SomeEntity
|
||||
{
|
||||
/**
|
||||
* @Orm\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\AnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $amenity;
|
||||
/**
|
||||
* @Orm\ManyToOne(targetEntity="Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\Fixture\AnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=true, referencedColumnName="uuid")
|
||||
*/
|
||||
private $amenityUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Orm\Entity
|
||||
*/
|
||||
class AnotherEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class AddUuidToEntityWhereMissingRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return AddUuidToEntityWhereMissingRector::class;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\InheritanceType(value="SINGLE_TABLE")
|
||||
*/
|
||||
abstract class ParentSingleTableInheritance
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddSingleTableInheritance extends ParentSingleTableInheritance
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\InheritanceType(value="SINGLE_TABLE")
|
||||
*/
|
||||
abstract class ParentSingleTableInheritance
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddSingleTableInheritance extends ParentSingleTableInheritance
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,64 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\InheritanceType(value="SINGLE_TABLE")
|
||||
*/
|
||||
abstract class ParentSingleTableInheritanceWithIdentifier
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddSingleTableInheritanceAgain extends ParentSingleTableInheritanceWithIdentifier
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\InheritanceType(value="SINGLE_TABLE")
|
||||
*/
|
||||
abstract class ParentSingleTableInheritanceWithIdentifier
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddSingleTableInheritanceAgain extends ParentSingleTableInheritanceWithIdentifier
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AlreadyHasConstructor
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = 5;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AlreadyHasConstructor
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = 5;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeEntityWithIntegerId
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeEntityWithIntegerId
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class ProcessStringId
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class ProcessStringId
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipIdWithUuidBinaryType
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="uuid_binary")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipIdWithUuidType
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="uuid")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Source\BaseEntityWithConstructor;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class WithParentConstructor extends BaseEntityWithConstructor
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Source\BaseEntityWithConstructor;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class WithParentConstructor extends BaseEntityWithConstructor
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="string")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\Source;
|
||||
|
||||
class BaseEntityWithConstructor
|
||||
{
|
||||
private $items;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->items = [];
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class AlwaysInitializeUuidInEntityRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return AlwaysInitializeUuidInEntityRector::class;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Source\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddUuidInit
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Source\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddUuidInit
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
public function __construct()
|
||||
{
|
||||
$this->superUuid = \Ramsey\Uuid\Uuid::uuid4();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Source\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddUuidInitToConstruct
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$one = 2;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Source\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddUuidInitToConstruct
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->superUuid = \Ramsey\Uuid\Uuid::uuid4();
|
||||
$one = 2;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class PreviousStepTest
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class PreviousStepTest
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
public function __construct()
|
||||
{
|
||||
$this->uuid = \Ramsey\Uuid\Uuid::uuid4();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Source\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SkipAlreadyAdded
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->superUuid = \Ramsey\Uuid\Uuid::uuid4();
|
||||
$one = 2;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\Source;
|
||||
|
||||
interface UuidInterface
|
||||
{
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ChangeIdenticalUuidToEqualsMethodCallRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return ChangeIdenticalUuidToEqualsMethodCallRector::class;
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector\Source\Building;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function match($checkedId): int
|
||||
{
|
||||
$building = new Building();
|
||||
|
||||
$isLeft = $building->getId() === $checkedId;
|
||||
$isRight = $checkedId === $building->getId();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector\Source\Building;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function match($checkedId): int
|
||||
{
|
||||
$building = new Building();
|
||||
|
||||
$isLeft = $building->getId()->equals(\Ramsey\Uuid\Uuid::fromString($checkedId));
|
||||
$isRight = $building->getId()->equals(\Ramsey\Uuid\Uuid::fromString($checkedId));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Identical\ChangeIdenticalUuidToEqualsMethodCallRector\Source;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
final class Building
|
||||
{
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ChangeGetUuidMethodCallToGetIdRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return ChangeGetUuidMethodCallToGetIdRector::class;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector\Source\Car;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$car = new Car();
|
||||
|
||||
return $car->getUuid()->toString();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector\Source\Car;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$car = new Car();
|
||||
|
||||
return $car->getId()->toString();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeGetUuidMethodCallToGetIdRector\Source;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Car
|
||||
{
|
||||
private $uuid;
|
||||
|
||||
public function getUuid(): UuidInterface
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class ChangeSetIdToUuidValueRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return ChangeSetIdToUuidValueRector::class;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setId(1);
|
||||
$buildingFirst->setUuid(Uuid::fromString('a3bfab84-e207-4ddd-b96d-488151de9e96'));
|
||||
|
||||
$buildingFirst2 = new Building();
|
||||
$buildingFirst2->setUuid('skip_this');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setId(Uuid::fromString('a3bfab84-e207-4ddd-b96d-488151de9e96'));
|
||||
|
||||
$buildingFirst2 = new Building();
|
||||
$buildingFirst2->setUuid('skip_this');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class NoSetUuid
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$car = new Building();
|
||||
$car->setId(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class NoSetUuid
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$car = new Building();
|
||||
$car->setId(\Ramsey\Uuid\Uuid::fromString('%s'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class OtherDirection
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setUuid(Uuid::fromString('a3bfab84-e207-4ddd-b96d-488151de9e96'));
|
||||
$buildingFirst->setId(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class OtherDirection
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setId(Uuid::fromString('a3bfab84-e207-4ddd-b96d-488151de9e96'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class WithConstant
|
||||
{
|
||||
const INTEGER_CONSTANT = 1;
|
||||
const UUID_CONSTANT = 'a3bfab84-e207-4ddd-b96d-488151de9e96';
|
||||
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setUuid(Uuid::fromString(self::UUID_CONSTANT));
|
||||
$buildingFirst->setId(self::INTEGER_CONSTANT);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class WithConstant
|
||||
{
|
||||
const INTEGER_CONSTANT = 1;
|
||||
const UUID_CONSTANT = 'a3bfab84-e207-4ddd-b96d-488151de9e96';
|
||||
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setId(Uuid::fromString(self::UUID_CONSTANT));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class WithIntConstantOnly
|
||||
{
|
||||
const INTEGER_CONSTANT = 1;
|
||||
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setId(self::INTEGER_CONSTANT);
|
||||
|
||||
// this values should be the same
|
||||
assert($buildingFirst->getId() === self::INTEGER_CONSTANT);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Fixture;
|
||||
|
||||
use Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source\Building;
|
||||
|
||||
class WithIntConstantOnly
|
||||
{
|
||||
const INTEGER_CONSTANT = '%s';
|
||||
|
||||
public function run()
|
||||
{
|
||||
$buildingFirst = new Building();
|
||||
$buildingFirst->setId(\Ramsey\Uuid\Uuid::fromString(self::INTEGER_CONSTANT));
|
||||
|
||||
// this values should be the same
|
||||
assert($buildingFirst->getId() === self::INTEGER_CONSTANT);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\MethodCall\ChangeSetIdToUuidValueRector\Source;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Building
|
||||
{
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class AddUuidAnnotationsToIdPropertyRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return AddUuidAnnotationsToIdPropertyRector::class;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(type="uuid_binary")
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeFixture
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
* @Serializer\Type("int")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\AddUuidAnnotationsToIdPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
|
||||
/**
|
||||
* @ORM\Table
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeFixture
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="uuid_binary")
|
||||
* @Serializer\Type("string")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\RemoveTemporaryUuidColumnPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* @ORM\Column
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column
|
||||
*/
|
||||
public $uuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\RemoveTemporaryUuidColumnPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* @ORM\Column
|
||||
*/
|
||||
public $id;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\RemoveTemporaryUuidColumnPropertyRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Property\RemoveTemporaryUuidColumnPropertyRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RemoveTemporaryUuidColumnPropertyRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return RemoveTemporaryUuidColumnPropertyRector::class;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\RemoveTemporaryUuidRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Phonenumber")
|
||||
*/
|
||||
private $apple;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Phonenumber")
|
||||
*/
|
||||
private $appleUuid;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\RemoveTemporaryUuidRelationPropertyRector\Fixture;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Phonenumber")
|
||||
*/
|
||||
private $apple;
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Doctrine\Rector\Property\RemoveTemporaryUuidRelationPropertyRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Doctrine\Rector\Property\RemoveTemporaryUuidRelationPropertyRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class RemoveTemporaryUuidRelationPropertyRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return RemoveTemporaryUuidRelationPropertyRector::class;
|
||||
}
|
||||
}
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class MultiExprsWithOrBothTruthy implements RunnableInterface
|
||||
class MultiExprsWithOrBothTruthy
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -32,9 +30,7 @@ class MultiExprsWithOrBothTruthy implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class MultiExprsWithOrBothTruthy implements RunnableInterface
|
||||
class MultiExprsWithOrBothTruthy
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class MultiExprsWithBoolOprnds implements RunnableInterface
|
||||
class MultiExprsWithBoolOprnds
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -32,9 +30,7 @@ class MultiExprsWithBoolOprnds implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class MultiExprsWithBoolOprnds implements RunnableInterface
|
||||
class MultiExprsWithBoolOprnds
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace Rector\Tests\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class SomeParent
|
||||
{
|
||||
public function speak()
|
||||
|
@ -24,7 +22,7 @@ class SomeChild extends SomeParent
|
|||
}
|
||||
}
|
||||
|
||||
class SomeRunnable implements RunnableInterface
|
||||
class SomeRunnable
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -39,8 +37,6 @@ class SomeRunnable implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class SomeParent
|
||||
{
|
||||
public function speak()
|
||||
|
@ -61,7 +57,7 @@ class SomeChild extends SomeParent
|
|||
}
|
||||
}
|
||||
|
||||
class SomeRunnable implements RunnableInterface
|
||||
class SomeRunnable
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\Assign\ListEachRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class ListEachNext implements RunnableInterface
|
||||
final class ListEachNext
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -24,9 +22,7 @@ final class ListEachNext implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\Assign\ListEachRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class ListEachNext implements RunnableInterface
|
||||
final class ListEachNext
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\Assign\ReplaceEachAssignmentWithKeyCurrentRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class ComparedResults implements RunnableInterface
|
||||
final class ComparedResults
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -23,9 +21,7 @@ final class ComparedResults implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\Assign\ReplaceEachAssignmentWithKeyCurrentRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class ComparedResults implements RunnableInterface
|
||||
final class ComparedResults
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\Assign\ReplaceEachAssignmentWithKeyCurrentRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class EachFixture implements RunnableInterface
|
||||
class EachFixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -22,9 +20,7 @@ class EachFixture implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\Assign\ReplaceEachAssignmentWithKeyCurrentRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
class EachFixture implements RunnableInterface
|
||||
class EachFixture
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\While_\WhileEachToForeachRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class PartialListInWhile implements RunnableInterface
|
||||
final class PartialListInWhile
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
@ -25,9 +23,7 @@ final class PartialListInWhile implements RunnableInterface
|
|||
|
||||
namespace Rector\Tests\Php72\Rector\While_\WhileEachToForeachRector\Fixture;
|
||||
|
||||
use Rector\Testing\Contract\RunnableInterface;
|
||||
|
||||
final class PartialListInWhile implements RunnableInterface
|
||||
final class PartialListInWhile
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
|
|
|
@ -16,8 +16,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
|
||||
*
|
||||
* @see \Rector\Tests\Autodiscovery\Rector\FileNode\MoveEntitiesToEntityDirectoryRector\MoveEntitiesToEntityDirectoryRectorTest
|
||||
|
|
|
@ -15,8 +15,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
|
||||
*
|
||||
* @see \Rector\Tests\Autodiscovery\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector\MoveInterfacesToContractNamespaceDirectoryRectorTest
|
||||
|
|
|
@ -18,8 +18,6 @@ use Symplify\SmartFileSystem\SmartFileInfo;
|
|||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
|
||||
*
|
||||
* @see \Rector\Tests\Autodiscovery\Rector\FileNode\MoveServicesBySuffixToDirectoryRector\MoveServicesBySuffixToDirectoryRectorTest
|
||||
|
|
|
@ -22,8 +22,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
* Inspiration @see https://github.com/rectorphp/rector/pull/1865/files#diff-0d18e660cdb626958662641b491623f8
|
||||
* @wip
|
||||
*
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\Autodiscovery\Rector\FileNode\MoveValueObjectsToValueObjectDirectoryRector\MoveValueObjectsToValueObjectDirectoryRectorTest
|
||||
*/
|
||||
final class MoveValueObjectsToValueObjectDirectoryRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
|
|
|
@ -27,8 +27,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Assign\ManualJsonStringToJsonEncodeArrayRector\ManualJsonStringToJsonEncodeArrayRectorTest
|
||||
*/
|
||||
final class ManualJsonStringToJsonEncodeArrayRector extends AbstractRector
|
||||
|
|
|
@ -16,8 +16,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://twitter.com/afilina & Zenika (CAN) for sponsoring this rule - visit them on https://zenika.ca/en/en
|
||||
*
|
||||
* @see \Rector\Tests\CodingStyle\Rector\ClassMethod\RemoveDoubleUnderscoreInMethodNameRector\RemoveDoubleUnderscoreInMethodNameRectorTest
|
||||
*/
|
||||
final class RemoveDoubleUnderscoreInMethodNameRector extends AbstractRector
|
||||
|
|
|
@ -24,8 +24,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector\AddArrayDefaultToArrayPropertyRectorTest
|
||||
* @see https://3v4l.org/dPlUg
|
||||
*/
|
||||
|
|
|
@ -12,8 +12,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://amateri.com for sponsoring this rule - visit them on https://www.startupjobs.cz/startup/scrumworks-s-r-o
|
||||
*
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Use_\SplitGroupedUseImportsRector\SplitGroupedUseImportsRectorTest
|
||||
*/
|
||||
final class SplitGroupedUseImportsRector extends AbstractRector
|
||||
|
|
|
@ -24,7 +24,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
* @see \Rector\Tests\DeadCode\Rector\Class_\RemoveUnusedDoctrineEntityMethodAndPropertyRector\RemoveUnusedDoctrineEntityMethodAndPropertyRectorTest
|
||||
*/
|
||||
final class RemoveUnusedDoctrineEntityMethodAndPropertyRector extends AbstractRector implements ZeroCacheRectorInterface
|
||||
|
|
|
@ -23,8 +23,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\DeadCode\Rector\Property\RemoveSetterOnlyPropertyAndMethodCallRector\RemoveSetterOnlyPropertyAndMethodCallRectorTest
|
||||
*/
|
||||
final class RemoveSetterOnlyPropertyAndMethodCallRector extends AbstractRector
|
||||
|
|
|
@ -22,8 +22,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://amateri.com for sponsoring this rule - visit them on https://www.startupjobs.cz/startup/scrumworks-s-r-o
|
||||
*
|
||||
* @see \Rector\Tests\Defluent\Rector\MethodCall\InArgChainFluentMethodCallToStandaloneMethodCallRectorTest\InArgChainFluentMethodCallToStandaloneMethodCallRectorTest
|
||||
*/
|
||||
final class InArgFluentChainMethodCallToStandaloneMethodCallRector extends AbstractRector
|
||||
|
|
|
@ -19,8 +19,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://amateri.com for sponsoring this rule - visit them on https://www.startupjobs.cz/startup/scrumworks-s-r-o
|
||||
*
|
||||
* @see \Rector\Tests\Defluent\Rector\MethodCall\MethodCallOnSetterMethodCallToStandaloneAssignRector\MethodCallOnSetterMethodCallToStandaloneAssignRectorTest
|
||||
*/
|
||||
final class MethodCallOnSetterMethodCallToStandaloneAssignRector extends AbstractRector
|
||||
|
|
|
@ -14,8 +14,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://amateri.com for sponsoring this rule - visit them on https://www.startupjobs.cz/startup/scrumworks-s-r-o
|
||||
*
|
||||
* @see \Rector\Tests\Defluent\Rector\Return_\DefluentReturnMethodCallRector\DefluentReturnMethodCallRectorTest
|
||||
*/
|
||||
final class DefluentReturnMethodCallRector extends AbstractRector
|
||||
|
|
|
@ -23,8 +23,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://amateri.com for sponsoring this rule - visit them on https://www.startupjobs.cz/startup/scrumworks-s-r-o
|
||||
*
|
||||
* @see \Rector\Tests\DependencyInjection\Rector\Class_\MultiParentingToAbstractDependencyRector\MultiParentingToAbstractDependencyRectorTest
|
||||
*/
|
||||
final class MultiParentingToAbstractDependencyRector extends AbstractRector implements ConfigurableRectorInterface
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Doctrine\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\Doctrine\Rector\ClassMethod\ChangeGetIdTypeToUuidRector\ChangeGetIdTypeToUuidRectorTest
|
||||
*/
|
||||
final class ChangeGetIdTypeToUuidRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var DoctrineDocBlockResolver
|
||||
*/
|
||||
private $doctrineDocBlockResolver;
|
||||
|
||||
public function __construct(DoctrineDocBlockResolver $doctrineDocBlockResolver)
|
||||
{
|
||||
$this->doctrineDocBlockResolver = $doctrineDocBlockResolver;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Change return type of getId() to uuid interface',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class GetId
|
||||
{
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class GetId
|
||||
{
|
||||
public function getId(): \Ramsey\Uuid\UuidInterface
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->doctrineDocBlockResolver->isInDoctrineEntityClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node, 'getId')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->hasUuidReturnType($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->returnType = new FullyQualified('Ramsey\Uuid\UuidInterface');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function hasUuidReturnType(ClassMethod $classMethod): bool
|
||||
{
|
||||
if ($classMethod->returnType === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($classMethod->returnType, 'Ramsey\Uuid\UuidInterface');
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Doctrine\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\DeadCode\Doctrine\DoctrineEntityManipulator;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\Tests\Doctrine\Rector\ClassMethod\ChangeReturnTypeOfClassMethodWithGetIdRector\ChangeReturnTypeOfClassMethodWithGetIdRectorTest
|
||||
*/
|
||||
final class ChangeReturnTypeOfClassMethodWithGetIdRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var DoctrineEntityManipulator
|
||||
*/
|
||||
private $doctrineEntityManipulator;
|
||||
|
||||
public function __construct(DoctrineEntityManipulator $doctrineEntityManipulator)
|
||||
{
|
||||
$this->doctrineEntityManipulator = $doctrineEntityManipulator;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change getUuid() method call to getId()', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getBuildingId(): int
|
||||
{
|
||||
$building = new Building();
|
||||
|
||||
return $building->getId();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function getBuildingId(): \Ramsey\Uuid\UuidInterface
|
||||
{
|
||||
$building = new Building();
|
||||
|
||||
return $building->getId();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node->returnType === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hasEntityGetIdMethodCall = $this->hasEntityGetIdMethodCall($node);
|
||||
if (! $hasEntityGetIdMethodCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->returnType = new FullyQualified('Ramsey\Uuid\UuidInterface');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function hasEntityGetIdMethodCall(ClassMethod $classMethod): bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node): bool {
|
||||
if (! $node instanceof Return_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($node->expr === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->doctrineEntityManipulator->isMethodCallOnDoctrineEntity($node->expr, 'getId');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Doctrine\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\Doctrine\Rector\ClassMethod\ChangeSetIdTypeToUuidRector\ChangeSetIdTypeToUuidRectorTest
|
||||
*/
|
||||
final class ChangeSetIdTypeToUuidRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var DoctrineDocBlockResolver
|
||||
*/
|
||||
private $doctrineDocBlockResolver;
|
||||
|
||||
public function __construct(DoctrineDocBlockResolver $doctrineDocBlockResolver)
|
||||
{
|
||||
$this->doctrineDocBlockResolver = $doctrineDocBlockResolver;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Change param type of setId() to uuid interface',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SetId
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function setId(int $uuid): int
|
||||
{
|
||||
return $this->id = $uuid;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SetId
|
||||
{
|
||||
private $id;
|
||||
|
||||
public function setId(\Ramsey\Uuid\UuidInterface $uuid): int
|
||||
{
|
||||
return $this->id = $uuid;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->doctrineDocBlockResolver->isInDoctrineEntityClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node, 'setId')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->renameUuidVariableToId($node);
|
||||
|
||||
// is already set?
|
||||
if ($node->params[0]->type !== null) {
|
||||
$currentType = $this->getName($node->params[0]->type);
|
||||
if ($currentType === 'Ramsey\Uuid\UuidInterface') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$node->params[0]->type = new FullyQualified('Ramsey\Uuid\UuidInterface');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function renameUuidVariableToId(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->traverseNodesWithCallable($classMethod, function (Node $node): ?Identifier {
|
||||
if (! $node instanceof Identifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node, 'uuid')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Identifier('id');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -21,8 +21,6 @@ use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://www.luzanky.cz/ for sponsoring this rule
|
||||
*
|
||||
* @see https://tomasvotruba.com/blog/2017/10/16/how-to-use-repository-with-doctrine-as-service-in-symfony/
|
||||
* @see https://getrector.org/blog/2021/02/08/how-to-instantly-decouple-symfony-doctrine-repository-inheritance-to-clean-composition
|
||||
*
|
||||
|
|
|
@ -1,322 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Doctrine\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
use PhpParser\Node\VarLikeIdentifier;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineRelationTagValueNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\Contract\Doctrine\ToOneTagNodeInterface;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\JoinColumnTagValueNode;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\OneToOneTagValueNode;
|
||||
use Rector\BetterPhpDocParser\ValueObjectFactory\PhpDocNode\Doctrine\JoinColumnTagValueNodeFactory;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||
use Rector\Doctrine\PhpDocParser\Ast\PhpDoc\PhpDocTagNodeFactory;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\Doctrine\Rector\Class_\AddUuidMirrorForRelationPropertyRector\AddUuidMirrorForRelationPropertyRectorTest
|
||||
*/
|
||||
final class AddUuidMirrorForRelationPropertyRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var PhpDocTagNodeFactory
|
||||
*/
|
||||
private $phpDocTagNodeFactory;
|
||||
|
||||
/**
|
||||
* @var UuidMigrationDataCollector
|
||||
*/
|
||||
private $uuidMigrationDataCollector;
|
||||
|
||||
/**
|
||||
* @var DoctrineDocBlockResolver
|
||||
*/
|
||||
private $doctrineDocBlockResolver;
|
||||
|
||||
/**
|
||||
* @var JoinColumnTagValueNodeFactory
|
||||
*/
|
||||
private $joinColumnTagValueNodeFactory;
|
||||
|
||||
/**
|
||||
* @var ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
|
||||
public function __construct(
|
||||
PhpDocTagNodeFactory $phpDocTagNodeFactory,
|
||||
UuidMigrationDataCollector $uuidMigrationDataCollector,
|
||||
DoctrineDocBlockResolver $doctrineDocBlockResolver,
|
||||
JoinColumnTagValueNodeFactory $joinColumnTagValueNodeFactory,
|
||||
ReflectionProvider $reflectionProvider
|
||||
) {
|
||||
$this->phpDocTagNodeFactory = $phpDocTagNodeFactory;
|
||||
$this->uuidMigrationDataCollector = $uuidMigrationDataCollector;
|
||||
$this->doctrineDocBlockResolver = $doctrineDocBlockResolver;
|
||||
$this->joinColumnTagValueNodeFactory = $joinColumnTagValueNodeFactory;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Adds $uuid property to entities, that already have $id with integer type.' .
|
||||
'Require for step-by-step migration from int to uuid.',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $amenity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AnotherEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeEntity
|
||||
{
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=false)
|
||||
*/
|
||||
private $amenity;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="AnotherEntity", cascade={"persist", "merge"})
|
||||
* @ORM\JoinColumn(nullable=true, referencedColumnName="uuid")
|
||||
*/
|
||||
private $amenityUuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AnotherEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
private $uuid;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
), ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->doctrineDocBlockResolver->isDoctrineEntityClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// traverse relations and see which of them have freshly added uuid on the other side
|
||||
foreach ($node->getProperties() as $property) {
|
||||
if ($this->shouldSkipProperty($node, $property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$node->stmts[] = $this->createMirrorNullable($property);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function shouldSkipProperty(Class_ $class, Property $property): bool
|
||||
{
|
||||
// this relation already is or has uuid property
|
||||
if ($this->isName($property, '*Uuid')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$uuidPropertyName = $this->getName($property) . 'Uuid';
|
||||
if ($this->hasClassPropertyName($class, $uuidPropertyName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$targetEntity = $this->doctrineDocBlockResolver->getTargetEntity($property);
|
||||
if ($targetEntity === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! $this->reflectionProvider->hasClass($targetEntity)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$classReflection = $this->reflectionProvider->getClass($targetEntity);
|
||||
if (! $classReflection->hasProperty('uuid')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
|
||||
$oneToOneTagValueNode = $propertyPhpDocInfo->getByType(OneToOneTagValueNode::class);
|
||||
// skip mappedBy oneToOne, as the column doesn't really exist
|
||||
if (! $oneToOneTagValueNode instanceof OneToOneTagValueNode) {
|
||||
return false;
|
||||
}
|
||||
return (bool) $oneToOneTagValueNode->getMappedBy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates duplicated property, that has "*uuidSuffix"
|
||||
* and nullable join column, so we cna complete them manually
|
||||
*/
|
||||
private function createMirrorNullable(Property $property): Property
|
||||
{
|
||||
$oldPropertyName = $this->getName($property);
|
||||
|
||||
$propertyWithUuid = clone $property;
|
||||
|
||||
// this is needed to keep old property name
|
||||
$this->mirrorPhpDocInfoToUuid($propertyWithUuid);
|
||||
|
||||
// name must be changed after the doc comment update, because the reflection annotation needed for update of doc comment
|
||||
// would miss non existing *Uuid property
|
||||
$uuidPropertyName = $oldPropertyName . 'Uuid';
|
||||
$newPropertyProperty = new PropertyProperty(new VarLikeIdentifier($uuidPropertyName));
|
||||
$propertyWithUuid->props = [$newPropertyProperty];
|
||||
|
||||
$this->addNewPropertyToCollector($property, $oldPropertyName, $uuidPropertyName);
|
||||
|
||||
return $propertyWithUuid;
|
||||
}
|
||||
|
||||
private function hasClassPropertyName(Class_ $class, string $uuidPropertyName): bool
|
||||
{
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if (! $this->isName($property, $uuidPropertyName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function mirrorPhpDocInfoToUuid(Property $property): void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
$newPropertyPhpDocInfo = clone $phpDocInfo;
|
||||
|
||||
$doctrineRelationTagValueNode = $phpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class);
|
||||
|
||||
if ($doctrineRelationTagValueNode instanceof ToManyTagNodeInterface) {
|
||||
$this->refactorToManyPropertyPhpDocInfo($newPropertyPhpDocInfo, $property);
|
||||
} elseif ($doctrineRelationTagValueNode instanceof ToOneTagNodeInterface) {
|
||||
$this->refactorToOnePropertyPhpDocInfo($newPropertyPhpDocInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private function addNewPropertyToCollector(
|
||||
Property $property,
|
||||
string $oldPropertyName,
|
||||
string $uuidPropertyName
|
||||
): void {
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
|
||||
$doctrineRelationTagValueNode = $phpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class);
|
||||
if (! $doctrineRelationTagValueNode instanceof DoctrineRelationTagValueNodeInterface) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var string $className */
|
||||
$className = $property->getAttribute(AttributeKey::CLASS_NAME);
|
||||
|
||||
$this->uuidMigrationDataCollector->addClassToManyRelationProperty(
|
||||
$className,
|
||||
$oldPropertyName,
|
||||
$uuidPropertyName,
|
||||
$doctrineRelationTagValueNode
|
||||
);
|
||||
}
|
||||
|
||||
private function refactorToManyPropertyPhpDocInfo(PhpDocInfo $phpDocInfo, Property $property): void
|
||||
{
|
||||
// replace @ORM\JoinColumn with @ORM\JoinTable
|
||||
$phpDocInfo->removeByType(JoinColumnTagValueNode::class);
|
||||
|
||||
$joinTableTagNode = $this->phpDocTagNodeFactory->createJoinTableTagNode($property);
|
||||
$phpDocInfo->addPhpDocTagNode($joinTableTagNode);
|
||||
}
|
||||
|
||||
private function refactorToOnePropertyPhpDocInfo(PhpDocInfo $propertyPhpDocInfo): void
|
||||
{
|
||||
/** @var JoinColumnTagValueNode|null $joinColumnTagValueNode */
|
||||
$joinColumnTagValueNode = $propertyPhpDocInfo->getByType(JoinColumnTagValueNode::class);
|
||||
|
||||
if ($joinColumnTagValueNode !== null) {
|
||||
// remove first
|
||||
$propertyPhpDocInfo->removeByType(JoinColumnTagValueNode::class);
|
||||
|
||||
$mirrorJoinColumnTagValueNode = $this->joinColumnTagValueNodeFactory->createFromItems([
|
||||
'referencedColumnName' => 'uuid',
|
||||
'unique' => $joinColumnTagValueNode->getUnique(),
|
||||
'nullable' => true,
|
||||
]);
|
||||
} else {
|
||||
$mirrorJoinColumnTagValueNode = $this->phpDocTagNodeFactory->createJoinColumnTagNode(true);
|
||||
}
|
||||
|
||||
$propertyPhpDocInfo->addTagValueNodeWithShortName($mirrorJoinColumnTagValueNode);
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Doctrine\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Doctrine\Collector\UuidMigrationDataCollector;
|
||||
use Rector\Doctrine\NodeFactory\EntityUuidNodeFactory;
|
||||
use Rector\Doctrine\Provider\EntityWithMissingUuidProvider;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\Doctrine\Rector\Class_\AddUuidToEntityWhereMissingRector\AddUuidToEntityWhereMissingRectorTest
|
||||
*
|
||||
* default value is initialized in @see AlwaysInitializeUuidInEntityRector
|
||||
*/
|
||||
final class AddUuidToEntityWhereMissingRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var EntityUuidNodeFactory
|
||||
*/
|
||||
private $entityUuidNodeFactory;
|
||||
|
||||
/**
|
||||
* @var UuidMigrationDataCollector
|
||||
*/
|
||||
private $uuidMigrationDataCollector;
|
||||
|
||||
/**
|
||||
* @var EntityWithMissingUuidProvider
|
||||
*/
|
||||
private $entityWithMissingUuidProvider;
|
||||
|
||||
public function __construct(
|
||||
EntityUuidNodeFactory $entityUuidNodeFactory,
|
||||
EntityWithMissingUuidProvider $entityWithMissingUuidProvider,
|
||||
UuidMigrationDataCollector $uuidMigrationDataCollector
|
||||
) {
|
||||
$this->entityUuidNodeFactory = $entityUuidNodeFactory;
|
||||
$this->uuidMigrationDataCollector = $uuidMigrationDataCollector;
|
||||
$this->entityWithMissingUuidProvider = $entityWithMissingUuidProvider;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Adds $uuid property to entities, that already have $id with integer type.' .
|
||||
'Require for step-by-step migration from int to uuid. ' .
|
||||
'In following step it should be renamed to $id and replace it', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeEntityWithIntegerId
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class SomeEntityWithIntegerId
|
||||
{
|
||||
/**
|
||||
* @var \Ramsey\Uuid\UuidInterface
|
||||
* @ORM\Column(type="uuid_binary", unique=true, nullable=true)
|
||||
*/
|
||||
private $uuid;
|
||||
/**
|
||||
* @var int
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
), ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$entitiesWithMissingUuidProperty = $this->entityWithMissingUuidProvider->provide();
|
||||
if (! in_array($node, $entitiesWithMissingUuidProperty, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// add to start of the class, so it can be easily seen
|
||||
$uuidProperty = $this->entityUuidNodeFactory->createTemporaryUuidProperty();
|
||||
$node->stmts = array_merge([$uuidProperty], $node->stmts);
|
||||
|
||||
/** @var string $class */
|
||||
$class = $this->getName($node);
|
||||
$this->uuidMigrationDataCollector->addClassAndColumnProperty($class, 'uuid');
|
||||
|
||||
return $node;
|
||||
}
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Doctrine\Rector\Class_;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use Rector\Core\NodeManipulator\ClassDependencyManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\Doctrine\NodeFactory\EntityUuidNodeFactory;
|
||||
use Rector\Doctrine\PhpDocParser\DoctrineDocBlockResolver;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @sponsor Thanks https://spaceflow.io/ for sponsoring this rule - visit them on https://github.com/SpaceFlow-app
|
||||
*
|
||||
* @see \Rector\Tests\Doctrine\Rector\Class_\AlwaysInitializeUuidInEntityRector\AlwaysInitializeUuidInEntityRectorTest
|
||||
*/
|
||||
final class AlwaysInitializeUuidInEntityRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var EntityUuidNodeFactory
|
||||
*/
|
||||
private $entityUuidNodeFactory;
|
||||
|
||||
/**
|
||||
* @var ClassDependencyManipulator
|
||||
*/
|
||||
private $classDependencyManipulator;
|
||||
|
||||
/**
|
||||
* @var DoctrineDocBlockResolver
|
||||
*/
|
||||
private $doctrineDocBlockResolver;
|
||||
|
||||
public function __construct(
|
||||
ClassDependencyManipulator $classDependencyManipulator,
|
||||
EntityUuidNodeFactory $entityUuidNodeFactory,
|
||||
DoctrineDocBlockResolver $doctrineDocBlockResolver
|
||||
) {
|
||||
$this->entityUuidNodeFactory = $entityUuidNodeFactory;
|
||||
$this->classDependencyManipulator = $classDependencyManipulator;
|
||||
$this->doctrineDocBlockResolver = $doctrineDocBlockResolver;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Add uuid initializion to all entities that misses it',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddUuidInit
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class AddUuidInit
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @var UuidInterface
|
||||
*/
|
||||
private $superUuid;
|
||||
public function __construct()
|
||||
{
|
||||
$this->superUuid = \Ramsey\Uuid\Uuid::uuid4();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->doctrineDocBlockResolver->isDoctrineEntityClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uuidProperty = $this->resolveUuidPropertyFromClass($node);
|
||||
if (! $uuidProperty instanceof Property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uuidPropertyName = $this->getName($uuidProperty);
|
||||
if ($this->hasUuidInitAlreadyAdded($node, $uuidPropertyName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$stmts = [];
|
||||
$stmts[] = $this->entityUuidNodeFactory->createUuidPropertyDefaultValueAssign($uuidPropertyName);
|
||||
|
||||
$this->classDependencyManipulator->addStmtsToConstructorIfNotThereYet($node, $stmts);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function resolveUuidPropertyFromClass(Class_ $class): ?Property
|
||||
{
|
||||
foreach ($class->getProperties() as $property) {
|
||||
$propertyPhpDoc = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
|
||||
$varType = $propertyPhpDoc->getVarType();
|
||||
if (! $varType instanceof ObjectType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! Strings::contains($varType->getClassName(), 'UuidInterface')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $property;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function hasUuidInitAlreadyAdded(Class_ $class, string $uuidPropertyName): bool
|
||||
{
|
||||
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
|
||||
if (! $constructClassMethod instanceof ClassMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->betterNodeFinder->findFirst($class->stmts, function (Node $node) use (
|
||||
$uuidPropertyName
|
||||
): bool {
|
||||
if (! $node instanceof Assign) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->nodeNameResolver->isStaticCallNamed($node->expr, 'Ramsey\Uuid\Uuid', 'uuid4')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node->var, $uuidPropertyName);
|
||||
});
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user