Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Downgrade PHP 7.3] Trailing commas in function calls
- Loading branch information
Tommy Quissens
committed
Sep 22, 2020
1 parent
c637ecc
commit 31d7749
Showing
7 changed files
with
135 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
rules/downgrade-php73/src/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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; | ||
|
||
/** | ||
* @see \Rector\DowngradePhp73\Tests\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector\DowngradeTrailingCommasInFunctionCallsRectorTest | ||
*/ | ||
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; | ||
} | ||
} |
70 changes: 0 additions & 70 deletions
70
rules/downgrade-php73/src/Rector/String_/DowngradeFlexibleHeredocSyntax.php
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...eTrailingCommasInFunctionCallsRector/DowngradeTrailingCommasInFunctionCallsRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ests/Rector/FuncCall/DowngradeTrailingCommasInFunctionCallsRector/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} | ||
|
||
?> |
31 changes: 0 additions & 31 deletions
31
...ests/Rector/String_/DowngradeFlexibleHeredocSyntax/DowngradeFlexibleHeredocSyntaxTest.php
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
...wngrade-php73/tests/Rector/String_/DowngradeFlexibleHeredocSyntax/Fixture/fixture.php.inc
This file was deleted.
Oops, something went wrong.