Skip to content

Commit

Permalink
Merge pull request #451 from mglaman/cmf-fix
Browse files Browse the repository at this point in the history
SymfonyCmfRoutingInClassMethodSignatureRule stop using isSuperOf
  • Loading branch information
mglaman authored Jul 14, 2022
2 parents 6ce70da + 72a57c4 commit ad47ecc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function processNode(Node $node, Scope $scope): array
foreach ($methodSignature->getParameters() as $parameter) {
foreach ($parameter->getType()->getReferencedClasses() as $referencedClass) {
$referencedClassType = new ObjectType($referencedClass);
if ($referencedClassType->isSuperTypeOf($cmfRouteObjectInterfaceType)->yes()) {
if ($cmfRouteObjectInterfaceType->equals($referencedClassType)) {
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -56,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
'\Drupal\Core\Routing\RouteObjectInterface'
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($referencedClassType->isSuperTypeOf($cmfRouteProviderInterfaceType)->yes()) {
} elseif ($cmfRouteProviderInterfaceType->equals($referencedClassType)) {
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -66,7 +66,7 @@ public function processNode(Node $node, Scope $scope): array
'\Drupal\Core\Routing\RouteProviderInterface'
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($referencedClassType->isSuperTypeOf($cmfLazyRouteCollectionType)->yes()) {
} elseif ($cmfLazyRouteCollectionType->equals($referencedClassType)) {
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -84,7 +84,7 @@ public function processNode(Node $node, Scope $scope): array
$returnClasses = $methodSignature->getReturnType()->getReferencedClasses();
foreach ($returnClasses as $returnClass) {
$returnType = new ObjectType($returnClass);
if ($returnType->isSuperTypeOf($cmfRouteObjectInterfaceType)->yes()) {
if ($cmfRouteObjectInterfaceType->equals($returnType)) {
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -94,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array
'\Drupal\Core\Routing\RouteObjectInterface'
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($returnType->isSuperTypeOf($cmfRouteProviderInterfaceType)->yes()) {
} elseif ($cmfRouteProviderInterfaceType->equals($returnType)) {
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -104,7 +104,7 @@ public function processNode(Node $node, Scope $scope): array
'\Drupal\Core\Routing\RouteProviderInterface'
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($returnType->isSuperTypeOf($cmfLazyRouteCollectionType)->yes()) {
} elseif ($cmfLazyRouteCollectionType->equals($returnType)) {
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand Down
6 changes: 6 additions & 0 deletions tests/src/Rules/data/symfony-cmf-routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function b(\Symfony\Cmf\Component\Routing\RouteProviderInterface $provide
public function c(\Symfony\Cmf\Component\Routing\LazyRouteCollection $collection) {

}
public function getIterator(): \Traversable {
return new \ArrayIterator([]);
}
}
class Bar {
public const NAME = \Drupal\Core\Routing\RouteObjectInterface::ROUTE_NAME;
Expand All @@ -29,5 +32,8 @@ public function b(\Drupal\Core\Routing\RouteProviderInterface $provider): \Drupa
}
public function c(\Drupal\Core\Routing\LazyRouteCollection $collection) {

}
public function d(): \Symfony\Component\Routing\RouteCollection {

}
}

0 comments on commit ad47ecc

Please sign in to comment.