Skip to content

Commit 7b6d5a3

Browse files
committed
Kick off AddNamespaceAliasRector rule.
1 parent 46e4f77 commit 7b6d5a3

9 files changed

Lines changed: 517 additions & 0 deletions

File tree

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\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class AddNamespaceAliasRectorTest 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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
4+
5+
use Doctrine\ODM\MongoDB\Mapping\Attribute\Document;
6+
use Doctrine\ODM\MongoDB\Mapping\Attribute\Id;
7+
use Doctrine\ODM\MongoDB\Mapping\Attribute\Version;
8+
use Some\OtherImport;
9+
10+
#[Document]
11+
final class Post
12+
{
13+
#[Id]
14+
private string $id;
15+
16+
#[Version]
17+
private int $version;
18+
}
19+
20+
?>
21+
-----
22+
<?php
23+
24+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
25+
26+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
27+
use Some\OtherImport;
28+
29+
#[ODM\Document]
30+
final class Post
31+
{
32+
#[ODM\Id]
33+
private string $id;
34+
35+
#[ODM\Version]
36+
private int $version;
37+
}
38+
39+
?>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
4+
5+
use Doctrine\ODM\MongoDB\Mapping\Attribute\{Document, EmbedOne as Embedded};
6+
use Doctrine\ODM\MongoDB\Mapping\Attribute\EmbedMany as Many;
7+
use Some\OtherImport;
8+
9+
#[Document]
10+
final class Blog
11+
{
12+
#[Embedded]
13+
public Post $post;
14+
15+
#[Many]
16+
public array $comments;
17+
}
18+
19+
?>
20+
-----
21+
<?php
22+
23+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
24+
25+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
26+
use Some\OtherImport;
27+
28+
#[ODM\Document]
29+
final class Blog
30+
{
31+
#[ODM\EmbedOne]
32+
public Post $post;
33+
34+
#[ODM\EmbedMany]
35+
public array $comments;
36+
}
37+
38+
?>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
4+
5+
use Doctrine\ORM\Mapping\Column;
6+
use Doctrine\ORM\Mapping\Entity;
7+
use Doctrine\ORM\Mapping\Id;
8+
use Some\OtherImport;
9+
10+
#[Entity]
11+
final class Article
12+
{
13+
#[Id]
14+
#[Column(type: 'integer')]
15+
public int $id;
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
23+
24+
use Doctrine\ORM\Mapping as ORM;
25+
use Some\OtherImport;
26+
27+
#[ORM\Entity]
28+
final class Article
29+
{
30+
#[ORM\Id]
31+
#[ORM\Column(type: 'integer')]
32+
public int $id;
33+
}
34+
35+
?>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
4+
5+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
6+
use Doctrine\ODM\MongoDB\Mapping\Attribute\Id;
7+
8+
#[ODM\Document]
9+
final class BlogPost
10+
{
11+
#[Id]
12+
private string $id;
13+
14+
#[ODM\Field]
15+
private string $title;
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
23+
24+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
25+
26+
#[ODM\Document]
27+
final class BlogPost
28+
{
29+
#[ODM\Id]
30+
private string $id;
31+
32+
#[ODM\Field]
33+
private string $title;
34+
}
35+
36+
?>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
4+
5+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
6+
7+
#[ODM\Document]
8+
final class BlogPost
9+
{
10+
#[ODM\Id]
11+
private string $id;
12+
13+
#[ODM\Field]
14+
private string $title;
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector\Fixture;
22+
23+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
24+
25+
#[ODM\Document]
26+
final class BlogPost
27+
{
28+
#[ODM\Id]
29+
private string $id;
30+
31+
#[ODM\Field]
32+
private string $title;
33+
}
34+
35+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Doctrine\CodeQuality\Rector\Namespace_\AddNamespaceAliasRector;
7+
use Rector\Doctrine\CodeQuality\ValueObject\NamespaceAlias;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->ruleWithConfiguration(AddNamespaceAliasRector::class, [
11+
new NamespaceAlias('Doctrine\\ORM\\Mapping', 'ORM'),
12+
new NamespaceAlias('Doctrine\\ODM\\MongoDB\\Mapping\\Attribute', 'ODM'),
13+
]);
14+
};

0 commit comments

Comments
 (0)