Skip to content

Commit d6265f5

Browse files
authored
[SYMFONY 4.2] replace Cookie argument values with constants (#818)
1 parent 97aafc5 commit d6265f5

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

config/sets/symfony/symfony4/symfony42/symfony42-http-foundation.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,34 @@
3434
null,
3535
'lax'
3636
),
37+
38+
new ReplaceArgumentDefaultValue(
39+
'Symfony\Component\HttpFoundation\Cookie',
40+
'__construct',
41+
8,
42+
'none',
43+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE'
44+
),
45+
new ReplaceArgumentDefaultValue(
46+
'Symfony\Component\HttpFoundation\Cookie',
47+
'create',
48+
8,
49+
'none',
50+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE'
51+
),
52+
new ReplaceArgumentDefaultValue(
53+
'Symfony\Component\HttpFoundation\Cookie',
54+
'create',
55+
8,
56+
'lax',
57+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_LAX'
58+
),
59+
new ReplaceArgumentDefaultValue(
60+
'Symfony\Component\HttpFoundation\Cookie',
61+
'create',
62+
8,
63+
'strict',
64+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT'
65+
),
3766
]);
3867
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Set\Symfony42\Fixture;
4+
5+
use Symfony\Component\HttpFoundation\Cookie;
6+
7+
class ReplaceNewCookieAndCreateParameterValue
8+
{
9+
public function run()
10+
{
11+
$cookie = Cookie::create('name', 'value', 0, '/', null, false, true, false, 'none');
12+
13+
return new Cookie('name', 'value', 0, '/', null, false, true, false, 'none');
14+
}
15+
}
16+
17+
?>
18+
19+
-----
20+
<?php
21+
22+
namespace Rector\Symfony\Tests\Set\Symfony42\Fixture;
23+
24+
use Symfony\Component\HttpFoundation\Cookie;
25+
26+
class ReplaceNewCookieAndCreateParameterValue
27+
{
28+
public function run()
29+
{
30+
$cookie = Cookie::create('name', 'value', 0, '/', null, false, true, false, \Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE);
31+
32+
return \Symfony\Component\HttpFoundation\Cookie::create('name', 'value', 0, '/', null, false, true, false, \Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE);
33+
}
34+
}
35+
36+
?>

tests/Set/Symfony42/Symfony42Test.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\Symfony42;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class Symfony42Test 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/symfony42.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_42]);
10+
};

0 commit comments

Comments
 (0)