Skip to content

Commit 967dc6e

Browse files
authored
[SYMFONY 5.1] replace Cookie withSameSite argument values with constants (#819)
1 parent d6265f5 commit 967dc6e

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

config/sets/symfony/symfony5/symfony51.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
$rectorConfig->import(__DIR__ . '/symfony51/symfony51-inflector.php');
1717
$rectorConfig->import(__DIR__ . '/symfony51/symfony51-notifier.php');
1818
$rectorConfig->import(__DIR__ . '/symfony51/symfony51-security-http.php');
19-
2019
};

config/sets/symfony/symfony5/symfony51/symfony51-http-foundation.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
declare(strict_types=1);
44

5+
use Rector\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;
6+
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
57
use Rector\Config\RectorConfig;
68
use Rector\Transform\Rector\StaticCall\StaticCallToNewRector;
79
use Rector\Transform\ValueObject\StaticCallToNew;
@@ -13,4 +15,27 @@
1315
new StaticCallToNew('Symfony\Component\HttpFoundation\RedirectResponse', 'create'),
1416
new StaticCallToNew('Symfony\Component\HttpFoundation\StreamedResponse', 'create'),
1517
]);
18+
$rectorConfig->ruleWithConfiguration(ReplaceArgumentDefaultValueRector::class, [
19+
new ReplaceArgumentDefaultValue(
20+
'Symfony\Component\HttpFoundation\Cookie',
21+
'withSameSite',
22+
0,
23+
'none',
24+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE'
25+
),
26+
new ReplaceArgumentDefaultValue(
27+
'Symfony\Component\HttpFoundation\Cookie',
28+
'withSameSite',
29+
0,
30+
'lax',
31+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_LAX'
32+
),
33+
new ReplaceArgumentDefaultValue(
34+
'Symfony\Component\HttpFoundation\Cookie',
35+
'withSameSite',
36+
0,
37+
'strict',
38+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT'
39+
),
40+
]);
1641
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Set\Symfony51\Fixture;
4+
5+
use Symfony\Component\HttpFoundation\Cookie;
6+
7+
class ReplaceCookieWithSameSiteParameterValue
8+
{
9+
public function run()
10+
{
11+
$cookie = Cookie::create('name');
12+
$cookie->withSameSite('none');
13+
14+
return $cookie;
15+
}
16+
}
17+
18+
?>
19+
20+
-----
21+
<?php
22+
23+
namespace Rector\Symfony\Tests\Set\Symfony51\Fixture;
24+
25+
use Symfony\Component\HttpFoundation\Cookie;
26+
27+
class ReplaceCookieWithSameSiteParameterValue
28+
{
29+
public function run()
30+
{
31+
$cookie = Cookie::create('name');
32+
$cookie->withSameSite(\Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE);
33+
34+
return $cookie;
35+
}
36+
}
37+
38+
?>

tests/Set/Symfony51/Symfony51Test.php

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\Set\Symfony51;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class Symfony51Test 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/symfony51.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\Set\SymfonySetList;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->sets([SymfonySetList::SYMFONY_51]);
10+
};

0 commit comments

Comments
 (0)