Skip to content

Commit 208b9ef

Browse files
authored
[doctrine-fixtures] Add AddGetReferenceTypeRector (#381)
* cs * [data-fixture] Add AddGetReferenceTypeRector
1 parent c2dac7b commit 208b9ef

18 files changed

Lines changed: 384 additions & 18 deletions

File tree

README.md

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,11 @@ To add a set to your config, use `->withPreparedSets` method, and pick one of co
2020
use Rector\Config\RectorConfig;
2121

2222
return RectorConfig::configure()
23-
->withPreparedSets(doctrineCodeQuality: true);
23+
->withPreparedSets(doctrineCodeQuality: true)
24+
->withComposerBased(doctrine: true);
2425
```
2526

26-
If you're on PHP 7.x, you can use withSets() instead, for `doctrineCodeQuality` set, so you can define:
27-
28-
```php
29-
use Rector\Config\RectorConfig;
30-
use Rector\Doctrine\Set\DoctrineSetList;
31-
32-
return RectorConfig::configure()
33-
->withSets([
34-
DoctrineSetList::DOCTRINE_CODE_QUALITY,
35-
]);
36-
```
37-
See [documentation](https://getrector.com/documentation)
27+
See [documentation](https://getrector.com/documentation) for more.
3828

3929
<br>
4030

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
"description": "Rector upgrades rules for Doctrine",
66
"require": {
77
"php": ">=8.2",
8-
"symfony/yaml": "^7.1"
8+
"symfony/yaml": "^7.2"
99
},
1010
"require-dev": {
1111
"doctrine/doctrine-bundle": "^2.13",
1212
"doctrine/orm": "^2.20",
1313
"phpstan/extension-installer": "^1.4",
14-
"phpstan/phpstan": "^2.1.8",
14+
"phpstan/phpstan": "^2.1.14",
1515
"phpstan/phpstan-deprecation-rules": "^2.0",
1616
"phpstan/phpstan-webmozart-assert": "^2.0",
1717
"phpunit/phpunit": "^11.5",
1818
"rector/rector-src": "dev-main",
19-
"rector/type-perfect": "^2.0",
19+
"rector/type-perfect": "^2.1",
2020
"phpecs/phpecs": "^2.1",
21-
"symplify/phpstan-rules": "^14.0",
21+
"symplify/phpstan-rules": "^14.6.9",
2222
"symplify/vendor-patches": "^11.3",
2323
"tomasvotruba/class-leak": "^2.0",
2424
"tracy/tracy": "^2.10"

config/sets/data-fixtures-16.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Doctrine\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->rules([AddGetReferenceTypeRector::class]);
10+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class AddGetReferenceTypeRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Fixture;
4+
5+
use Doctrine\Common\DataFixtures\AbstractFixture;
6+
use Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomeEntity;
7+
8+
final class SimpleGetReference extends AbstractFixture
9+
{
10+
public function run(SomeEntity $someEntity)
11+
{
12+
$someEntity->setSomePassedEntity(
13+
$this->getReference('some-id')
14+
);
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Fixture;
23+
24+
use Doctrine\Common\DataFixtures\AbstractFixture;
25+
use Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomeEntity;
26+
27+
final class SimpleGetReference extends AbstractFixture
28+
{
29+
public function run(SomeEntity $someEntity)
30+
{
31+
$someEntity->setSomePassedEntity(
32+
$this->getReference('some-id', \Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomePassedEntity::class)
33+
);
34+
}
35+
}
36+
37+
?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Fixture;
4+
5+
use Doctrine\Common\DataFixtures\AbstractFixture;
6+
use Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomeEntity;
7+
use Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomePassedEntity;
8+
9+
final class SkipAlreadyFilledType extends AbstractFixture
10+
{
11+
public function run(SomeEntity $someEntity)
12+
{
13+
$someEntity->setSomePassedEntity(
14+
$this->getReference('some-id', SomePassedEntity::class)
15+
);
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Fixture;
4+
5+
use Doctrine\Common\DataFixtures\AbstractFixture;
6+
use Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomeEntity;
7+
8+
final class SimpleGetReference
9+
{
10+
public function run(SomeEntity $someEntity)
11+
{
12+
$someEntity->setSomePassedEntity(
13+
$this->getReference('some-id')
14+
);
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Fixture;
4+
5+
use Doctrine\Common\DataFixtures\AbstractFixture;
6+
use Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source\SomeEntity;
7+
8+
final class SkipOutsideGetter extends AbstractFixture
9+
{
10+
public function run(SomeEntity $someEntity)
11+
{
12+
$unableToResolve = $this->getReference('some-id');
13+
$someEntity->setSomePassedEntity(
14+
$unableToResolve
15+
);
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source;
6+
7+
final class SomeEntity
8+
{
9+
public function setSomePassedEntity(?SomePassedEntity $somePassedEntity)
10+
{
11+
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\DoctrineFixture\Rector\MethodCall\AddGetReferenceTypeRector\Source;
4+
5+
class SomePassedEntity
6+
{
7+
}

0 commit comments

Comments
 (0)