Skip to content

Commit 31b2367

Browse files
committed
[SYMFONY 4.2] replace Cookie argument values with constants
1 parent aaabd63 commit 31b2367

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

config/sets/symfony/symfony4/symfony42.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
$rectorConfig->import(__DIR__ . '/symfony42/symfony42-serializer.php');
2020
$rectorConfig->import(__DIR__ . '/symfony42/symfony42-form.php');
2121
$rectorConfig->import(__DIR__ . '/symfony42/symfony42-cache.php');
22+
$rectorConfig->import(__DIR__ . '/symfony42/symfony42-weblink.php');
2223
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
'__construct',
14+
8,
15+
'none',
16+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE'
17+
),
18+
new ReplaceArgumentDefaultValue(
19+
'Symfony\Component\HttpFoundation\Cookie',
20+
'create',
21+
8,
22+
'none',
23+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_NONE'
24+
),
25+
new ReplaceArgumentDefaultValue(
26+
'Symfony\Component\HttpFoundation\Cookie',
27+
'create',
28+
8,
29+
'lax',
30+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_LAX'
31+
),
32+
new ReplaceArgumentDefaultValue(
33+
'Symfony\Component\HttpFoundation\Cookie',
34+
'create',
35+
8,
36+
'strict',
37+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT'
38+
),
39+
]);
40+
};
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+
?>
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)