Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/drupal-9/drupal-9.1-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector;
use DrupalRector\Rector\Deprecation\AssertCacheTagRector;
use DrupalRector\Rector\Deprecation\AssertElementNotPresentRector;
use DrupalRector\Rector\Deprecation\AssertElementPresentRector;
Expand Down Expand Up @@ -182,4 +183,5 @@
$rectorConfig->rule(GetRawContentRector::class);
$rectorConfig->rule(GetAllOptionsRector::class);
$rectorConfig->rule(UserPasswordRector::class);
$rectorConfig->rule(SymfonyCmfRouteObjectInterfaceConstantsRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace DrupalRector\Rector\ConstFetch;

use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @changelog https://www.drupal.org/node/3151009
*
* @see \Rector\Tests\DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector\SymfonyCmfRouteObjectInterfaceConstantsRectorTest
*/
final class SymfonyCmfRouteObjectInterfaceConstantsRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('"Replaces constant calls on \Symfony\Cmf\Component\Routing\RouteObjectInterface to \Drupal\Core\Routing\RouteObjectInterface"', [
new CodeSample(
<<<'CODE_SAMPLE'
class SomeClass
{
public const NAME = \Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_NAME;
public const OBJECT = \Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT;
public const CONTROLLER = \Symfony\Cmf\Component\Routing\RouteObjectInterface::CONTROLLER_NAME;
}
CODE_SAMPLE

,
<<<'CODE_SAMPLE'
class SomeClass
{
public const NAME = \Drupal\Core\Routing\RouteObjectInterface::ROUTE_NAME;
public const OBJECT = \Drupal\Core\Routing\RouteObjectInterface::ROUTE_OBJECT;
public const CONTROLLER = \Drupal\Core\Routing\RouteObjectInterface::CONTROLLER_NAME;
}
CODE_SAMPLE

)
]);
}

/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [\PhpParser\Node\Expr\ClassConstFetch::class];
}

/**
* @param \PhpParser\Node\Expr\ClassConstFetch $node
*/
public function refactor(Node $node): ?Node
{
$cmfRouteObjectInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteObjectInterface::class);
if (!$this->isObjectType($node->class, $cmfRouteObjectInterfaceType)) {
return $node;
}

$node->class = new FullyQualified(\Drupal\Core\Routing\RouteObjectInterface::class);
return $node;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\Tests\DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector\Fixture;

class SomeClass
{
public const NAME = \Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_NAME;
public const OBJECT = \Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT;
public const CONTROLLER = \Symfony\Cmf\Component\Routing\RouteObjectInterface::CONTROLLER_NAME;
}

?>
-----
<?php

namespace Rector\Tests\DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector\Fixture;

class SomeClass
{
public const NAME = \Drupal\Core\Routing\RouteObjectInterface::ROUTE_NAME;
public const OBJECT = \Drupal\Core\Routing\RouteObjectInterface::ROUTE_OBJECT;
public const CONTROLLER = \Drupal\Core\Routing\RouteObjectInterface::CONTROLLER_NAME;
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class SymfonyCmfRouteObjectInterfaceConstantsRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(\Symplify\SmartFileSystem\SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

/**
* @return \Iterator<\Symplify\SmartFileSystem\SmartFileInfo>
*/
public function provideData(): \Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(\DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector::class);
};