Skip to content

Commit

Permalink
[CodingStyle] Handle direct pass string config on ConsistentPregDelim…
Browse files Browse the repository at this point in the history
…iterRector (#1780)
  • Loading branch information
samsonasik committed Feb 8, 2022
1 parent ea69b90 commit c7e4ba9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class DirectStringConfigTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureDirectStringConfig');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/direct_string_configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector\Fixture;

class Fixture
{
public function run()
{
preg_match('~value~', $value);
preg_match_all('~value~im', $value);
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector\Fixture;

class Fixture
{
public function run()
{
preg_match('/value/', $value);
preg_match_all('/value/im', $value);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ConsistentPregDelimiterRector::class)
->configure(['/']);
};
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function refactor(Node $node): ?Node

public function configure(array $configuration): void
{
$this->delimiter = $configuration[self::DELIMITER] ?? '#';
$this->delimiter = $configuration[self::DELIMITER] ?? (string) current($configuration);
}

private function refactorFuncCall(FuncCall $funcCall): ?FuncCall
Expand Down

0 comments on commit c7e4ba9

Please sign in to comment.