mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
[Phalcon 4.0] Add FlashWithCssClassesToExtraCallRector
This commit is contained in:
parent
d337f6e6e7
commit
9f1b745592
@ -102,7 +102,8 @@
|
|||||||
"Rector\\Utils\\RectorGenerator\\": "utils/RectorGenerator/src",
|
"Rector\\Utils\\RectorGenerator\\": "utils/RectorGenerator/src",
|
||||||
"Rector\\StrictCodeQuality\\": "packages/StrictCodeQuality/src",
|
"Rector\\StrictCodeQuality\\": "packages/StrictCodeQuality/src",
|
||||||
"Rector\\DynamicTypeAnalysis\\": "packages/DynamicTypeAnalysis/src",
|
"Rector\\DynamicTypeAnalysis\\": "packages/DynamicTypeAnalysis/src",
|
||||||
"Rector\\PhpDeglobalize\\": "packages/PhpDeglobalize/src"
|
"Rector\\PhpDeglobalize\\": "packages/PhpDeglobalize/src",
|
||||||
|
"Rector\\Phalcon\\": "packages/Phalcon/src"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
@ -160,7 +161,8 @@
|
|||||||
"Rector\\ZendToSymfony\\Tests\\": "packages/ZendToSymfony/tests",
|
"Rector\\ZendToSymfony\\Tests\\": "packages/ZendToSymfony/tests",
|
||||||
"Rector\\StrictCodeQuality\\Tests\\": "packages/StrictCodeQuality/tests",
|
"Rector\\StrictCodeQuality\\Tests\\": "packages/StrictCodeQuality/tests",
|
||||||
"Rector\\DynamicTypeAnalysis\\Tests\\": "packages/DynamicTypeAnalysis/tests",
|
"Rector\\DynamicTypeAnalysis\\Tests\\": "packages/DynamicTypeAnalysis/tests",
|
||||||
"Rector\\PhpDeglobalize\\Tests\\": "packages/PhpDeglobalize/tests"
|
"Rector\\PhpDeglobalize\\Tests\\": "packages/PhpDeglobalize/tests",
|
||||||
|
"Rector\\Phalcon\\Tests\\": "packages/Phalcon/tests"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"packages/Symfony/tests/Rector/FrameworkBundle/AbstractToConstructorInjectionRectorSource",
|
"packages/Symfony/tests/Rector/FrameworkBundle/AbstractToConstructorInjectionRectorSource",
|
||||||
|
@ -114,3 +114,4 @@ services:
|
|||||||
Rector\Renaming\Rector\ConstFetch\RenameConstantRector:
|
Rector\Renaming\Rector\ConstFetch\RenameConstantRector:
|
||||||
FILTER_SPECIAL_CHARS: 'FILTER_SPECIAL'
|
FILTER_SPECIAL_CHARS: 'FILTER_SPECIAL'
|
||||||
FILTER_ALPHANUM: 'FILTER_ALNUM'
|
FILTER_ALPHANUM: 'FILTER_ALNUM'
|
||||||
|
Rector\Phalcon\Rector\Assign\FlashWithCssClassesToExtraCallRector: ~
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Rector\Phalcon\Rector\Assign;
|
||||||
|
|
||||||
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Expr\Assign;
|
||||||
|
use Rector\Rector\AbstractRector;
|
||||||
|
use Rector\RectorDefinition\CodeSample;
|
||||||
|
use Rector\RectorDefinition\RectorDefinition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://github.com/rectorphp/rector/issues/2408#issue-534441142
|
||||||
|
*
|
||||||
|
* @see \Rector\Phalcon\Tests\Rector\Assign\FlashWithCssClassesToExtraCallRector\FlashWithCssClassesToExtraCallRectorTest
|
||||||
|
*/
|
||||||
|
final class FlashWithCssClassesToExtraCallRector extends AbstractRector
|
||||||
|
{
|
||||||
|
public function getDefinition(): RectorDefinition
|
||||||
|
{
|
||||||
|
return new RectorDefinition('Add $cssClasses in Flash to separated method call', [
|
||||||
|
new CodeSample(
|
||||||
|
<<<'PHP'
|
||||||
|
class SomeClass {
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$cssClasses = [];
|
||||||
|
$flash = new Phalcon\Flash($cssClasses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PHP
|
||||||
|
,
|
||||||
|
<<<'PHP'
|
||||||
|
class SomeClass {
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$cssClasses = [];
|
||||||
|
$flash = new Phalcon\Flash();
|
||||||
|
$flash->setCssClasses($cssClasses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PHP
|
||||||
|
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getNodeTypes(): array
|
||||||
|
{
|
||||||
|
return [Assign::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Assign $node
|
||||||
|
*/
|
||||||
|
public function refactor(Node $node): ?Node
|
||||||
|
{
|
||||||
|
if (! $node->expr instanceof Node\Expr\New_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->isName($node->expr->class, 'Phalcon\Flash')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($node->expr->args[0])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$argument = $node->expr->args[0];
|
||||||
|
|
||||||
|
// remove arg
|
||||||
|
unset($node->expr->args[0]);
|
||||||
|
|
||||||
|
// change the node
|
||||||
|
|
||||||
|
$variable = $node->var;
|
||||||
|
$setCssClassesMethodCall = new Node\Expr\MethodCall($variable, 'setCssClasses', [$argument]);
|
||||||
|
|
||||||
|
$this->addNodeAfterNode($setCssClassesMethodCall, $node);
|
||||||
|
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\Phalcon\Tests\Rector\Assign\FlashWithCssClassesToExtraCallRector\Fixture;
|
||||||
|
|
||||||
|
class SomeClass {
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$cssClasses = [];
|
||||||
|
$flash = new \Phalcon\Flash($cssClasses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
-----
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rector\Phalcon\Tests\Rector\Assign\FlashWithCssClassesToExtraCallRector\Fixture;
|
||||||
|
|
||||||
|
class SomeClass {
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$cssClasses = [];
|
||||||
|
$flash = new \Phalcon\Flash();
|
||||||
|
$flash->setCssClasses($cssClasses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Rector\Phalcon\Tests\Rector\Assign\FlashWithCssClassesToExtraCallRector;
|
||||||
|
|
||||||
|
use Iterator;
|
||||||
|
use Rector\Phalcon\Rector\Assign\FlashWithCssClassesToExtraCallRector;
|
||||||
|
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||||
|
|
||||||
|
final class FlashWithCssClassesToExtraCallRectorTest extends AbstractRectorTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider provideDataForTest()
|
||||||
|
*/
|
||||||
|
public function test(string $file): void
|
||||||
|
{
|
||||||
|
$this->doTestFile($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideDataForTest(): Iterator
|
||||||
|
{
|
||||||
|
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRectorClass(): string
|
||||||
|
{
|
||||||
|
return FlashWithCssClassesToExtraCallRector::class;
|
||||||
|
}
|
||||||
|
}
|
25
rector.yaml
25
rector.yaml
@ -19,23 +19,22 @@ parameters:
|
|||||||
# @see utils/RectorGenerator/config/config.yaml
|
# @see utils/RectorGenerator/config/config.yaml
|
||||||
rector_recipe:
|
rector_recipe:
|
||||||
# run "bin/rector create" to create a new Rector + tests from this config
|
# run "bin/rector create" to create a new Rector + tests from this config
|
||||||
package: "Rector"
|
package: "Phalcon"
|
||||||
name: "SwapClassMethodArgumentsRector"
|
name: "FlashWithCssClassesToExtraCallRector"
|
||||||
node_types:
|
node_types:
|
||||||
# put main node first, it is used to create namespace
|
# put main node first, it is used to create namespace
|
||||||
- "StaticCall"
|
- "Assign"
|
||||||
- "MethodCall"
|
|
||||||
- "ClassMethod"
|
|
||||||
|
|
||||||
description: "Reorder class method arguments, including their calls"
|
description: "Add $cssClasses in Flash to separated method call"
|
||||||
code_before: >
|
code_before: >
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SomeClass
|
class SomeClass
|
||||||
{
|
{
|
||||||
public static function run($first, $second)
|
public function run()
|
||||||
{
|
{
|
||||||
self::run($first, $second);
|
$cssClasses = [];
|
||||||
|
$flash = new Phalcon\Flash($cssClasses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,12 +43,14 @@ parameters:
|
|||||||
|
|
||||||
class SomeClass
|
class SomeClass
|
||||||
{
|
{
|
||||||
public static function run($second, $first)
|
public function run()
|
||||||
{
|
{
|
||||||
self::run($second, $first);
|
$cssClasses = [];
|
||||||
|
$flash = new Phalcon\Flash();
|
||||||
|
$flash->setCssClasses($cssClasses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
source: # e.g. link to RFC or headline in upgrade guide, 1 or more in the list
|
source: # e.g. link to RFC or headline in upgrade guide, 1 or more in the list
|
||||||
- ""
|
- "https://github.com/rectorphp/rector/issues/2408#issue-534441142"
|
||||||
set: "" # e.g. symfony30, target config to append this rector to
|
set: "phalcon40" # e.g. symfony30, target config to append this rector to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user