Skip to content

Commit 97aafc5

Browse files
authored
[SYMFONY 3.2] replace Cookie argument values with constants (#817)
1 parent 493b13f commit 97aafc5

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed

config/sets/symfony/symfony3/symfony32.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
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

79
return static function (RectorConfig $rectorConfig): void {
810
$rectorConfig->import(__DIR__ . '/symfony32/symfony32-dependency-injection.php');
11+
$rectorConfig->import(__DIR__ . '/symfony32/symfony32-http-foundation.php');
912
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
11+
$rectorConfig->ruleWithConfiguration(ReplaceArgumentDefaultValueRector::class, [
12+
new ReplaceArgumentDefaultValue(
13+
'Symfony\Component\HttpFoundation\Cookie',
14+
'__construct',
15+
8,
16+
'lax',
17+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_LAX'
18+
),
19+
new ReplaceArgumentDefaultValue(
20+
'Symfony\Component\HttpFoundation\Cookie',
21+
'__construct',
22+
8,
23+
'strict',
24+
'Symfony\Component\HttpFoundation\Cookie::SAMESITE_STRICT'
25+
),
26+
]);
27+
};

src/Set/SetProvider/Symfony3SetProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ public function provide(): array
136136
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony32/symfony32-dependency-injection.php'
137137
),
138138

139+
new ComposerTriggeredSet(
140+
SetGroup::SYMFONY,
141+
'symfony/http-foundation',
142+
'3.2',
143+
__DIR__ . '/../../../config/sets/symfony/symfony3/symfony32/symfony32-http-foundation.php'
144+
),
145+
139146
new ComposerTriggeredSet(
140147
SetGroup::SYMFONY,
141148
'symfony/symfony',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\Set\Symfony32\Fixture;
4+
5+
use Symfony\Component\HttpFoundation\Cookie;
6+
7+
class ReplaceNewCookieParameterValue
8+
{
9+
public function run()
10+
{
11+
return new Cookie('name', 'value', 0, '/', null, false, true, false, 'lax');
12+
}
13+
}
14+
15+
?>
16+
17+
-----
18+
<?php
19+
20+
namespace Rector\Symfony\Tests\Set\Symfony32\Fixture;
21+
22+
use Symfony\Component\HttpFoundation\Cookie;
23+
24+
class ReplaceNewCookieParameterValue
25+
{
26+
public function run()
27+
{
28+
return new Cookie('name', 'value', 0, '/', null, false, true, false, \Symfony\Component\HttpFoundation\Cookie::SAMESITE_LAX);
29+
}
30+
}
31+
32+
?>

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

0 commit comments

Comments
 (0)