mirror of
https://github.com/rectorphp/rector.git
synced 2024-08-12 11:30:23 +00:00
Add rector for ShopRegistration
This commit is contained in:
parent
a48fe8cd98
commit
787a401fbe
@ -8,3 +8,4 @@ services:
|
||||
sendCookies: sendHeaders
|
||||
setBody: setContent
|
||||
Rector\Shopware\Rector\ClassConstFetch\ShopwareVersionConstsRector: ~
|
||||
Rector\Shopware\Rector\MethodCall\ShopRegistrationServiceRector: ~
|
||||
|
@ -0,0 +1,73 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Shopware\Rector\MethodCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
/**
|
||||
* @see https://github.com/shopware/shopware/blob/5.6/UPGRADE-5.6.md
|
||||
*/
|
||||
final class ShopRegistrationServiceRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Replace $shop->registerResources() with ShopRegistrationService', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$shop = new \Shopware\Models\Shop\Shop();
|
||||
$shop->registerResources();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$shop = new \Shopware\Models\Shop\Shop();
|
||||
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [MethodCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MethodCall $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->isName($node, 'registerResources')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isType($node, 'Shopware\Models\Shop\Shop')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$shopwareFunction = new FuncCall(new Node\Name('Shopware'));
|
||||
$containerCall = new MethodCall($shopwareFunction, new Node\Identifier('Container'));
|
||||
$methodCall = new MethodCall($containerCall, new Node\Identifier('get'), [new Node\Arg(new Node\Scalar\String_('shopware.components.shop_registration_service'))]);
|
||||
|
||||
return new MethodCall($methodCall, new Node\Identifier('registerShop'), [new Node\Arg($node->var)]);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Shopware\Tests\Rector\MethodCall\ShopRegistrationServiceRector\Fixture;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$shop = new \Shopware\Models\Shop\Shop();
|
||||
$shop->registerResources();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Shopware\Tests\Rector\MethodCall\ShopRegistrationServiceRector\Fixture;
|
||||
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$shop = new \Shopware\Models\Shop\Shop();
|
||||
Shopware()->Container()->get('shopware.components.shop_registration_service')->registerShop($shop);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,20 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Shopware\Tests\Rector\MethodCall\ShopRegistrationServiceRector;
|
||||
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class ShopRegistrationServiceRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFiles([
|
||||
__DIR__ . '/Fixture/fixture.php.inc'
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return \Rector\Shopware\Rector\MethodCall\ShopRegistrationServiceRector::class;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user