Skip to content

Commit c4c7974

Browse files
committed
[Symfony62] Replace attributes #264
1 parent 5f0c972 commit c4c7974

File tree

11 files changed

+185
-2
lines changed

11 files changed

+185
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Symfony\Set\SymfonyLevelSetList;
7+
use Rector\Symfony\Set\SymfonySetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->sets([SymfonySetList::SYMFONY_62, SymfonyLevelSetList::UP_TO_SYMFONY_60]);
11+
};

config/sets/symfony/symfony43.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types=1);
44

55
use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
6-
76
use Rector\Arguments\ValueObject\ArgumentAdder;
87
use Rector\Config\RectorConfig;
98
use Rector\Core\ValueObject\MethodName;

config/sets/symfony/symfony60.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare(strict_types=1);
44

55
use PhpParser\Node\Scalar\String_;
6-
76
use PHPStan\Type\MixedType;
87
use PHPStan\Type\ObjectType;
98
use Rector\Config\RectorConfig;

config/sets/symfony/symfony62.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Renaming\Rector\Name\RenameClassRector;
7+
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
// https://symfony.com/blog/new-in-symfony-6-2-built-in-cache-security-template-and-doctrine-attributes
11+
$rectorConfig->ruleWithConfiguration(
12+
RenameClassRector::class,
13+
[
14+
// @see https://github.com/symfony/symfony/pull/46907
15+
'Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted' => 'Symfony\Component\Security\Http\Attribute\IsGranted',
16+
// @see https://github.com/symfony/symfony/pull/46880
17+
'Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache' => 'Symfony\Component\HttpKernel\Attribute\Cache',
18+
// @see https://github.com/symfony/symfony/pull/46906
19+
'Sensio\Bundle\FrameworkExtraBundle\Configuration\Template' => 'Symfony\Bridge\Twig\Attribute\Template',
20+
],
21+
);
22+
};

src/Set/SymfonyLevelSetList.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,9 @@ final class SymfonyLevelSetList implements SetListInterface
107107
* @var string
108108
*/
109109
final public const UP_TO_SYMFONY_60 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-60.php';
110+
111+
/**
112+
* @var string
113+
*/
114+
final public const UP_TO_SYMFONY_62 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-60.php';
110115
}

src/Set/SymfonySetList.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ final class SymfonySetList implements SetListInterface
123123
*/
124124
final public const SYMFONY_60 = __DIR__ . '/../../config/sets/symfony/symfony60.php';
125125

126+
/**
127+
* @var string
128+
*/
129+
final public const SYMFONY_62 = __DIR__ . '/../../config/sets/symfony/symfony62.php';
130+
126131
/**
127132
* @var string
128133
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
4+
use Symfony\Component\HttpFoundation\Response;
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
class ReplaceSensioIsCache
8+
{
9+
#[Route('/cache', name: 'cache')]
10+
#[Cache(expired: 'tomorrow')]
11+
public function cache(): Response
12+
{
13+
return new Response();
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
use Symfony\Component\HttpFoundation\Response;
22+
use Symfony\Component\Routing\Annotation\Route;
23+
24+
class ReplaceSensioIsCache
25+
{
26+
#[Route('/cache', name: 'cache')]
27+
#[\Symfony\Component\HttpKernel\Attribute\Cache(expired: 'tomorrow')]
28+
public function cache(): Response
29+
{
30+
return new Response();
31+
}
32+
}
33+
34+
?>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
4+
use Symfony\Component\HttpFoundation\Response;
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
class ReplaceSensioIsGranted
8+
{
9+
#[Route('/is/granted', name: 'is_granted')]
10+
#[IsGranted('IS_AUTHENTICATED_FULLY')]
11+
public function isGranted(): Response
12+
{
13+
return new Response();
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
use Symfony\Component\HttpFoundation\Response;
22+
use Symfony\Component\Routing\Annotation\Route;
23+
24+
class ReplaceSensioIsGranted
25+
{
26+
#[Route('/is/granted', name: 'is_granted')]
27+
#[\Symfony\Component\Security\Http\Attribute\IsGranted('IS_AUTHENTICATED_FULLY')]
28+
public function isGranted(): Response
29+
{
30+
return new Response();
31+
}
32+
}
33+
34+
?>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
4+
use Symfony\Component\HttpFoundation\Response;
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
class ReplaceSensioTemplate
8+
{
9+
#[Route('/template', name: 'template')]
10+
#[Template('templates/foo.html.twig', vars: ['bar', 'buz'])]
11+
public function template($bar, $baz = 'abc', $buz = 'def'): Response
12+
{
13+
return new Response();
14+
}
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
use Symfony\Component\HttpFoundation\Response;
22+
use Symfony\Component\Routing\Annotation\Route;
23+
24+
class ReplaceSensioTemplate
25+
{
26+
#[Route('/template', name: 'template')]
27+
#[\Symfony\Bridge\Twig\Attribute\Template('templates/foo.html.twig', vars: ['bar', 'buz'])]
28+
public function template($bar, $baz = 'abc', $buz = 'def'): Response
29+
{
30+
return new Response();
31+
}
32+
}
33+
34+
?>

tests/Set/Symfony62/Symfony62Test.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Symfony\Tests\Set\Symfony62;
6+
7+
use Iterator;
8+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
9+
10+
final class Symfony62Test extends AbstractRectorTestCase
11+
{
12+
/**
13+
* @dataProvider provideData()
14+
*/
15+
public function test(string $filePath): void
16+
{
17+
$this->doTestFile($filePath);
18+
}
19+
20+
public function provideData(): Iterator
21+
{
22+
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
23+
}
24+
25+
public function provideConfigFilePath(): string
26+
{
27+
return __DIR__ . '/config/symfony62.php';
28+
}
29+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy