mirror of
https://github.com/rectorphp/rector.git
synced 2024-07-30 21:30:23 +00:00
[Symfony] Add use_strict_mode removal
This commit is contained in:
parent
ff7a457c47
commit
3e124e3d2b
@ -1,5 +1,8 @@
|
||||
services:
|
||||
# yaml
|
||||
# covers https://github.com/symfony/symfony/pull/24523
|
||||
Rector\Symfony\Rector\Yaml\SessionStrictTrueByDefaultYamlRector: ~
|
||||
|
||||
Rector\YamlRector\Rector\ReplaceStringYamlRector:
|
||||
$oldToNewString:
|
||||
' !php/object:': ' !php/object '
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\Rector\Yaml;
|
||||
|
||||
use Nette\Utils\Strings;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
use Rector\YamlRector\Contract\YamlRectorInterface;
|
||||
|
||||
final class SessionStrictTrueByDefaultYamlRector implements YamlRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const USE_STRICT_MODE_PATTERN = '#(^session:)(.*?)(\n +use_strict_mode: true)#s';
|
||||
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('session > use_strict_mode is true by default and can be removed', [
|
||||
new CodeSample('session > use_strict_mode: true', 'session:'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function isCandidate(string $content): bool
|
||||
{
|
||||
return (bool) Strings::matchAll($content, self::USE_STRICT_MODE_PATTERN);
|
||||
}
|
||||
|
||||
public function refactor(string $content): string
|
||||
{
|
||||
return Strings::replace($content, self::USE_STRICT_MODE_PATTERN, '$1$2');
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
session:
|
||||
another: option
|
@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\Tests\Yaml\SessionStrictTrueByDefaultYamlRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\YamlRector\Tests\AbstractYamlRectorTest;
|
||||
|
||||
/**
|
||||
* @covers \Rector\Symfony\Rector\Yaml\SessionStrictTrueByDefaultYamlRector
|
||||
*/
|
||||
final class SessionStrictTrueByDefaultYamlRectorTest extends AbstractYamlRectorTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideWrongToFixedFiles()
|
||||
*/
|
||||
public function test(string $wrong, string $fixed): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent($wrong, $fixed);
|
||||
}
|
||||
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Wrong/wrong.yml', __DIR__ . '/Correct/correct.yml'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
{
|
||||
return __DIR__ . '/config.yml';
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
session:
|
||||
another: option
|
||||
use_strict_mode: true
|
@ -0,0 +1,4 @@
|
||||
services:
|
||||
Rector\Symfony\Rector\Yaml\SessionStrictTrueByDefaultYamlRector: ~
|
||||
|
||||
# covers https://github.com/symfony/symfony/pull/24523
|
Loading…
Reference in New Issue
Block a user