Skip to content

Commit 62d3ce5

Browse files
committed
[SYMFONY 5.1] replace Cookie withSameSite argument values with constants
1 parent aaabd63 commit 62d3ce5

File tree

6 files changed

+117
-1
lines changed

6 files changed

+117
-1
lines changed

config/sets/symfony/symfony5/symfony51.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
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-
19+
$rectorConfig->import(__DIR__ . '/symfony51/symfony51-web-link.php');
2020
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector;
6+
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
7+
use Rector\Config\RectorConfig;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->ruleWithConfiguration(ReplaceArgumentDefaultValueRector::class, [
11+
new ReplaceArgumentDefaultValue(
12+
'Symfony\Component\HttpFoundation\Cookie',
13+
'withSameSite',
14+
0,
15+
'none',
16+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE'
17+
),
18+
new ReplaceArgumentDefaultValue(
19+
'Symfony\Component\HttpFoundation\Cookie',
20+
'withSameSite',
21+
0,
22+
'lax',
23+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_LAX'
24+
),
25+
new ReplaceArgumentDefaultValue(
26+
'Symfony\Component\HttpFoundation\Cookie',
27+
'withSameSite',
28+
0,
29+
'strict',
30+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT'
31+
),
32+
]);
33+
};

src/Set/SetProvider/Symfony5SetProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ public function provide(): array
125125
__DIR__ . '/../../../config/sets/symfony/symfony5/symfony51/symfony51-security-core.php'
126126
),
127127

128+
new ComposerTriggeredSet(
129+
SetGroup::SYMFONY,
130+
'symfony/web-link',
131+
'5.1',
132+
__DIR__ . '/../../../config/sets/symfony/symfony5/symfony51/symfony51-web-link.php'
133+
),
134+
128135
new ComposerTriggeredSet(
129136
SetGroup::SYMFONY,
130137
'symfony/symfony',
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+
?>
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)