[Phalcon] Drop custom rules, the framework does not have enough traction (#5313)

This commit is contained in:
Tomas Votruba 2021-01-25 18:34:49 +01:00 committed by GitHub
parent f489a4ab6b
commit 402a212737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 0 additions and 624 deletions

View File

@ -138,7 +138,6 @@
"Rector\\PHPUnit\\": "rules/phpunit/src",
"Rector\\PSR4\\": "rules/psr4/src",
"Rector\\Performance\\": "rules/performance/src",
"Rector\\Phalcon\\": "rules/phalcon/src",
"Rector\\Php52\\": "rules/php52/src",
"Rector\\Php53\\": "rules/php53/src",
"Rector\\Php54\\": "rules/php54/src",
@ -262,7 +261,6 @@
"Rector\\PHPUnit\\Tests\\": "rules/phpunit/tests",
"Rector\\PSR4\\Tests\\": "rules/psr4/tests",
"Rector\\Performance\\Tests\\": "rules/performance/tests",
"Rector\\Phalcon\\Tests\\": "rules/phalcon/tests",
"Rector\\Php52\\Tests\\": "rules/php52/tests",
"Rector\\Php53\\Tests\\": "rules/php53/tests",
"Rector\\Php54\\Tests\\": "rules/php54/tests",

View File

@ -13,9 +13,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(OrderPrivateMethodsByUseRector::class);
$services->set(OrderClassConstantsByIntegerValueRector::class);
$services->set(OrderMethodsByVisibilityRector::class);
$services->set(OrderPropertiesByVisibilityRector::class);
$services->set(OrderConstantsByVisibilityRector::class);

View File

@ -4,9 +4,6 @@ declare(strict_types=1);
use Rector\Generic\Rector\StaticCall\SwapClassMethodArgumentsRector;
use Rector\Generic\ValueObject\SwapClassMethodArguments;
use Rector\Phalcon\Rector\Assign\FlashWithCssClassesToExtraCallRector;
use Rector\Phalcon\Rector\Assign\NewApplicationToToFactoryWithDefaultContainerRector;
use Rector\Phalcon\Rector\MethodCall\AddRequestToHandleMethodCallRector;
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
@ -138,10 +135,4 @@ return static function (ContainerConfigurator $containerConfigurator): void {
'FILTER_ALPHANUM' => 'FILTER_ALNUM',
],
]]);
$services->set(FlashWithCssClassesToExtraCallRector::class);
$services->set(NewApplicationToToFactoryWithDefaultContainerRector::class);
$services->set(AddRequestToHandleMethodCallRector::class);
};

View File

@ -1,94 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @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 getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Add $cssClasses in Flash to separated method call',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$cssClasses = [];
$flash = new Phalcon\Flash($cssClasses);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
$cssClasses = [];
$flash = new Phalcon\Flash();
$flash->setCssClasses($cssClasses);
}
}
CODE_SAMPLE
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [Assign::class];
}
/**
* @param Assign $node
*/
public function refactor(Node $node): ?Node
{
if (! $node->expr instanceof 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 MethodCall($variable, 'setCssClasses', [$argument]);
$this->addNodeAfterNode($setCssClassesMethodCall, $node);
return $node;
}
}

View File

@ -1,103 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Rector\Assign;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name\FullyQualified;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/rectorphp/rector/issues/2408
*
* @see \Rector\Phalcon\Tests\Rector\Assign\NewApplicationToToFactoryWithDefaultContainerRector\NewApplicationToToFactoryWithDefaultContainerRectorTest
*/
final class NewApplicationToToFactoryWithDefaultContainerRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change new application to default factory with application',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($di)
{
$application = new \Phalcon\Mvc\Application($di);
$response = $application->handle();
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($di)
{
$container = new \Phalcon\Di\FactoryDefault();
$application = new \Phalcon\Mvc\Application($container);
$response = $application->handle($_SERVER["REQUEST_URI"]);
}
}
CODE_SAMPLE
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [Assign::class];
}
/**
* @param Assign $node
*/
public function refactor(Node $node): ?Node
{
if (! $this->isNewApplication($node->expr)) {
return null;
}
if (! $node->expr instanceof New_) {
return null;
}
$containerVariable = new Variable('container');
$factoryAssign = $this->createNewContainerToFactoryDefaultAssign($containerVariable);
$node->expr->args = [new Arg($containerVariable)];
$this->addNodeBeforeNode($factoryAssign, $node);
return $node;
}
private function isNewApplication(Expr $expr): bool
{
if (! $expr instanceof New_) {
return false;
}
return $this->isName($expr->class, 'Phalcon\Mvc\Application');
}
private function createNewContainerToFactoryDefaultAssign(Variable $variable): Assign
{
return new Assign($variable, new New_(new FullyQualified('Phalcon\Di\FactoryDefault')));
}
}

View File

@ -1,91 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/rectorphp/rector/issues/2408
*/
/**
* @see \Rector\Phalcon\Tests\Rector\MethodCall\AddRequestToHandleMethodCallRector\AddRequestToHandleMethodCallRectorTest
*/
final class AddRequestToHandleMethodCallRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Add $_SERVER REQUEST_URI to method call', [
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($di)
{
$application = new \Phalcon\Mvc\Application();
$response = $application->handle();
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run($di)
{
$application = new \Phalcon\Mvc\Application();
$response = $application->handle($_SERVER["REQUEST_URI"]);
}
}
CODE_SAMPLE
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node): ?Node
{
if (! $this->isObjectType($node->var, 'Phalcon\Mvc\Application')) {
return null;
}
if (! $this->isName($node->name, 'handle')) {
return null;
}
if ($node->args === null) {
return null;
}
if ($node->args !== []) {
return null;
}
$node->args[] = new Arg($this->createServerRequestUri());
return $node;
}
private function createServerRequestUri(): ArrayDimFetch
{
return new ArrayDimFetch(new Variable('_SERVER'), new String_('REQUEST_URI'));
}
}

View File

@ -1,84 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/rectorphp/rector/issues/2571
*
* @see \Rector\Phalcon\Tests\Rector\MethodCall\DecoupleSaveMethodCallWithArgumentToAssignRector\DecoupleSaveMethodCallWithArgumentToAssignRectorTest
*/
final class DecoupleSaveMethodCallWithArgumentToAssignRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Decouple Phalcon\Mvc\Model::save() with argument to assign()',
[
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(\Phalcon\Mvc\Model $model, $data)
{
$model->save($data);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
class SomeClass
{
public function run(\Phalcon\Mvc\Model $model, $data)
{
$model->save();
$model->assign($data);
}
}
CODE_SAMPLE
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node): ?Node
{
if (! $this->isObjectType($node->var, 'Phalcon\Mvc\Model')) {
return null;
}
if (! $this->isName($node->name, 'save')) {
return null;
}
if ($node->args === []) {
return null;
}
$assignMethodCall = $this->createMethodCall($node->var, 'assign');
$assignMethodCall->args = $node->args;
$node->args = [];
$this->addNodeAfterNode($assignMethodCall, $node);
return $node;
}
}

View File

@ -1,30 +0,0 @@
<?php
namespace Rector\Phalcon\Tests\Rector\Assign\FlashWithCssClassesToExtraCallRector\Fixture;
class Fixture
{
public function run()
{
$cssClasses = [];
$flash = new \Phalcon\Flash($cssClasses);
}
}
?>
-----
<?php
namespace Rector\Phalcon\Tests\Rector\Assign\FlashWithCssClassesToExtraCallRector\Fixture;
class Fixture
{
public function run()
{
$cssClasses = [];
$flash = new \Phalcon\Flash();
$flash->setCssClasses($cssClasses);
}
}
?>

View File

@ -1,31 +0,0 @@
<?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;
use Symplify\SmartFileSystem\SmartFileInfo;
final class FlashWithCssClassesToExtraCallRectorTest extends AbstractRectorTestCase
{
/**
* @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 FlashWithCssClassesToExtraCallRector::class;
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace Rector\Phalcon\Tests\Rector\Assign\NewApplicationToToFactoryWithDefaultContainerRector\Fixture;
class Fixture
{
public function run($di)
{
$application = new \Phalcon\Mvc\Application($di);
}
}
?>
-----
<?php
namespace Rector\Phalcon\Tests\Rector\Assign\NewApplicationToToFactoryWithDefaultContainerRector\Fixture;
class Fixture
{
public function run($di)
{
$container = new \Phalcon\Di\FactoryDefault();
$application = new \Phalcon\Mvc\Application($container);
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Tests\Rector\Assign\NewApplicationToToFactoryWithDefaultContainerRector;
use Iterator;
use Rector\Phalcon\Rector\Assign\NewApplicationToToFactoryWithDefaultContainerRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class NewApplicationToToFactoryWithDefaultContainerRectorTest extends AbstractRectorTestCase
{
/**
* @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 NewApplicationToToFactoryWithDefaultContainerRector::class;
}
}

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Tests\Rector\MethodCall\AddRequestToHandleMethodCallRector;
use Iterator;
use Rector\Phalcon\Rector\MethodCall\AddRequestToHandleMethodCallRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class AddRequestToHandleMethodCallRectorTest extends AbstractRectorTestCase
{
/**
* @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 AddRequestToHandleMethodCallRector::class;
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace Rector\Phalcon\Tests\Rector\MethodCall\AddRequestToHandleMethodCallRector\Fixture;
class Fixture
{
public function run($di)
{
$application = new \Phalcon\Mvc\Application();
$response = $application->handle();
}
}
?>
-----
<?php
namespace Rector\Phalcon\Tests\Rector\MethodCall\AddRequestToHandleMethodCallRector\Fixture;
class Fixture
{
public function run($di)
{
$application = new \Phalcon\Mvc\Application();
$response = $application->handle($_SERVER['REQUEST_URI']);
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Phalcon\Tests\Rector\MethodCall\DecoupleSaveMethodCallWithArgumentToAssignRector;
use Iterator;
use Rector\Phalcon\Rector\MethodCall\DecoupleSaveMethodCallWithArgumentToAssignRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class DecoupleSaveMethodCallWithArgumentToAssignRectorTest extends AbstractRectorTestCase
{
/**
* @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 DecoupleSaveMethodCallWithArgumentToAssignRector::class;
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace Rector\Phalcon\Tests\Rector\MethodCall\DecoupleSaveMethodCallWithArgumentToAssignRector\Fixture;
class Fixture
{
public function run(\Phalcon\Mvc\Model $model, $data)
{
$model->save($data);
}
}
?>
-----
<?php
namespace Rector\Phalcon\Tests\Rector\MethodCall\DecoupleSaveMethodCallWithArgumentToAssignRector\Fixture;
class Fixture
{
public function run(\Phalcon\Mvc\Model $model, $data)
{
$model->save();
$model->assign($data);
}
}
?>