Skip to content

Commit 2eb7139

Browse files
authored
[code-quality] Add InlineClassRoutePrefixRector (#701)
1 parent 3fb5171 commit 2eb7139

File tree

10 files changed

+415
-7
lines changed

10 files changed

+415
-7
lines changed

config/sets/symfony/symfony-code-quality.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\Config\RectorConfig;
66
use Rector\Symfony\CodeQuality\Rector\BinaryOp\ResponseStatusCodeRector;
77
use Rector\Symfony\CodeQuality\Rector\Class_\EventListenerToEventSubscriberRector;
8+
use Rector\Symfony\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector;
89
use Rector\Symfony\CodeQuality\Rector\Class_\LoadValidatorMetadataToAnnotationRector;
910
use Rector\Symfony\CodeQuality\Rector\ClassMethod\ActionSuffixRemoverRector;
1011
use Rector\Symfony\CodeQuality\Rector\ClassMethod\ParamTypeFromRouteRequiredRegexRector;
@@ -30,5 +31,8 @@
3031

3132
// tests
3233
AssertSameResponseCodeWithDebugContentsRector::class,
34+
35+
// routing
36+
InlineClassRoutePrefixRector::class,
3337
]);
3438
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\Routing\Annotation\Route;
7+
8+
/**
9+
* @Route(path="/city")
10+
*/
11+
final class ExplicitSilentMix extends Controller
12+
{
13+
/**
14+
* @Route("/street")
15+
*/
16+
public function some()
17+
{
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
26+
27+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28+
use Symfony\Component\Routing\Annotation\Route;
29+
30+
final class ExplicitSilentMix extends Controller
31+
{
32+
/**
33+
* @Route("/city/street")
34+
*/
35+
public function some()
36+
{
37+
}
38+
}
39+
40+
?>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\Routing\Annotation\Route;
7+
8+
/**
9+
* @Route("/city")
10+
*/
11+
final class InversedExplicitSilentMix extends Controller
12+
{
13+
/**
14+
* @Route(path="/street")
15+
*/
16+
public function some()
17+
{
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
26+
27+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28+
use Symfony\Component\Routing\Annotation\Route;
29+
30+
final class InversedExplicitSilentMix extends Controller
31+
{
32+
/**
33+
* @Route(path="/city/street")
34+
*/
35+
public function some()
36+
{
37+
}
38+
}
39+
40+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
4+
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
/**
8+
* @Route("/city")
9+
*/
10+
final class SkipNoController
11+
{
12+
/**
13+
* @Route("/street")
14+
*/
15+
public function some()
16+
{
17+
}
18+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\Routing\Annotation\Route;
7+
8+
/**
9+
* @Route("/city")
10+
*/
11+
final class SomeRoutingClass extends Controller
12+
{
13+
/**
14+
* @Route("/street")
15+
*/
16+
public function some()
17+
{
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector\Fixture;
26+
27+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28+
use Symfony\Component\Routing\Annotation\Route;
29+
30+
final class SomeRoutingClass extends Controller
31+
{
32+
/**
33+
* @Route("/city/street")
34+
*/
35+
public function some()
36+
{
37+
}
38+
}
39+
40+
?>
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\Symfony\Tests\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class InlineClassRoutePrefixRectorTest 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: 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\Symfony\CodeQuality\Rector\Class_\InlineClassRoutePrefixRector;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->rule(InlineClassRoutePrefixRector::class);
10+
};

0 commit comments

Comments
 (0)