Skip to content

Commit

Permalink
[Downgrade PHP 7.3] Trailing commas in function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Quissens committed Sep 22, 2020
1 parent c637ecc commit 99b5e0c
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 139 deletions.
5 changes: 2 additions & 3 deletions config/set/downgrade-php73.php
Expand Up @@ -2,11 +2,10 @@

declare(strict_types=1);

use Rector\DowngradePhp73\Rector\FuncCall\DowngradeTrailingCommasInFunctionCalls;
use Rector\DowngradePhp73\Rector\String_\DowngradeFlexibleHeredocSyntax;
use Rector\DowngradePhp73\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(DowngradeFlexibleHeredocSyntax::class);
$services->set(DowngradeTrailingCommasInFunctionCallsRector::class);
};
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Rector\DowngradePhp73\Rector\FuncCall;

use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\NodeTypeResolver\Node\AttributeKey;

final class DowngradeTrailingCommasInFunctionCallsRector extends AbstractRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition(
'Remove trailing commas in function calls', [
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(string $value)
{
$compacted = compact(
'posts',
'units',
);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function __construct(string $value)
{
$compacted = compact(
'posts',
'units'
);
}
}
CODE_SAMPLE
),
]
);
}

/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}

public function refactor(Node $node): ?Node
{
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
return $node;
}
}

This file was deleted.

@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Rector\DowngradePhp73\Tests\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector;

use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp73\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector;
use Symplify\SmartFileSystem\SmartFileInfo;

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

public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

protected function getRectorClass(): string
{
return DowngradeTrailingCommasInFunctionCallsRector::class;
}

protected function getPhpVersion(): string
{
return '7.2';
// TODO: create constant
// return PhpVersionFeature::;
}
}
@@ -0,0 +1,27 @@
<?php

namespace Rector\DowngradePhp73\Tests\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector\Fixture;

class FixtureClass
{
public function run()
{
$compacted = compact('posts','units',);
}
}

?>
-----
<?php

namespace Rector\DowngradePhp73\Tests\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector\Fixture;

class FixtureClass
{
public function run()
{
$compacted = compact('posts', 'units');
}
}

?>

This file was deleted.

This file was deleted.

0 comments on commit 99b5e0c

Please sign in to comment.