Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Symfony62] Replace attributes #264 #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/sets/symfony/level/up-to-symfony-62.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([SymfonySetList::SYMFONY_62, SymfonyLevelSetList::UP_TO_SYMFONY_60]);
};
1 change: 0 additions & 1 deletion config/sets/symfony/symfony43.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;

use Rector\Arguments\ValueObject\ArgumentAdder;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\MethodName;
Expand Down
1 change: 0 additions & 1 deletion config/sets/symfony/symfony60.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use PhpParser\Node\Scalar\String_;

use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use Rector\Config\RectorConfig;
Expand Down
21 changes: 21 additions & 0 deletions config/sets/symfony/symfony62.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;

return static function (RectorConfig $rectorConfig): void {
// https://symfony.com/blog/new-in-symfony-6-2-built-in-cache-security-template-and-doctrine-attributes
$rectorConfig->ruleWithConfiguration(
RenameClassRector::class,
[
// @see https://github.com/symfony/symfony/pull/46907
'Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted' => 'Symfony\Component\Security\Http\Attribute\IsGranted',
// @see https://github.com/symfony/symfony/pull/46880
'Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache' => 'Symfony\Component\HttpKernel\Attribute\Cache',
// @see https://github.com/symfony/symfony/pull/46906
'Sensio\Bundle\FrameworkExtraBundle\Configuration\Template' => 'Symfony\Bridge\Twig\Attribute\Template',
],
);
};
5 changes: 5 additions & 0 deletions src/Set/SymfonyLevelSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ final class SymfonyLevelSetList implements SetListInterface
* @var string
*/
final public const UP_TO_SYMFONY_60 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-60.php';

/**
* @var string
*/
final public const UP_TO_SYMFONY_62 = __DIR__ . '/../../config/sets/symfony/level/up-to-symfony-62.php';
}
5 changes: 5 additions & 0 deletions src/Set/SymfonySetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ final class SymfonySetList implements SetListInterface
*/
final public const SYMFONY_60 = __DIR__ . '/../../config/sets/symfony/symfony60.php';

/**
* @var string
*/
final public const SYMFONY_62 = __DIR__ . '/../../config/sets/symfony/symfony62.php';

/**
* @var string
*/
Expand Down
34 changes: 34 additions & 0 deletions tests/Set/Symfony62/Fixture/replace_sensio_cache.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ReplaceSensioIsCache
{
#[Route('/cache', name: 'cache')]
#[Cache(expired: 'tomorrow')]
public function cache(): Response
{
return new Response();
}
}

?>
-----
<?php

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ReplaceSensioIsCache
{
#[Route('/cache', name: 'cache')]
#[\Symfony\Component\HttpKernel\Attribute\Cache(expired: 'tomorrow')]
public function cache(): Response
{
return new Response();
}
}

?>
34 changes: 34 additions & 0 deletions tests/Set/Symfony62/Fixture/replace_sensio_is_granted.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ReplaceSensioIsGranted
{
#[Route('/is/granted', name: 'is_granted')]
#[IsGranted('IS_AUTHENTICATED_FULLY')]
public function isGranted(): Response
{
return new Response();
}
}

?>
-----
<?php

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ReplaceSensioIsGranted
{
#[Route('/is/granted', name: 'is_granted')]
#[\Symfony\Component\Security\Http\Attribute\IsGranted('IS_AUTHENTICATED_FULLY')]
public function isGranted(): Response
{
return new Response();
}
}

?>
34 changes: 34 additions & 0 deletions tests/Set/Symfony62/Fixture/replace_sensio_template.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ReplaceSensioTemplate
{
#[Route('/template', name: 'template')]
#[Template('templates/foo.html.twig', vars: ['bar', 'buz'])]
public function template($bar, $baz = 'abc', $buz = 'def'): Response
{
return new Response();
}
}

?>
-----
<?php

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ReplaceSensioTemplate
{
#[Route('/template', name: 'template')]
#[\Symfony\Bridge\Twig\Attribute\Template('templates/foo.html.twig', vars: ['bar', 'buz'])]
public function template($bar, $baz = 'abc', $buz = 'def'): Response
{
return new Response();
}
}

?>
29 changes: 29 additions & 0 deletions tests/Set/Symfony62/Symfony62Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\Set\Symfony62;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class Symfony62Test extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/symfony62.php';
}
}
11 changes: 11 additions & 0 deletions tests/Set/Symfony62/config/symfony62.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../config/config.php');
$rectorConfig->sets([SymfonySetList::SYMFONY_62]);
};