[Symfony] Add use_strict_mode removal

This commit is contained in:
Tomas Votruba 2018-07-18 22:08:57 +02:00
parent ff7a457c47
commit 3e124e3d2b
6 changed files with 75 additions and 0 deletions

View File

@ -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 '

View File

@ -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');
}
}

View File

@ -0,0 +1,2 @@
session:
another: option

View File

@ -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';
}
}

View File

@ -0,0 +1,3 @@
session:
another: option
use_strict_mode: true

View File

@ -0,0 +1,4 @@
services:
Rector\Symfony\Rector\Yaml\SessionStrictTrueByDefaultYamlRector: ~
# covers https://github.com/symfony/symfony/pull/24523