Skip to content

Commit e9008b6

Browse files
authored
[CodeQuality] Skip DateTimeInterface instance on ControllerMethodInjectionToConstructorRector (#921)
* [CodeQuality] Skip DateTime on ControllerMethodInjectionToConstructorRector * Fix
1 parent 691c46b commit e9008b6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Fixture;
6+
7+
use DateTimeImmutable;
8+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9+
use Symfony\Component\Routing\Annotation\Route;
10+
11+
final class SkipDateTime extends AbstractController
12+
{
13+
#[Route('/some-action', name: 'some_action')]
14+
public function someAction(DateTimeImmutable $d)
15+
{
16+
}
17+
}
18+
19+
?>

rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ public function refactor(Node $node): ?Node
164164
continue;
165165
}
166166

167-
if ($this->isObjectType($param->type, new ObjectType(SymfonyClass::USER_INTERFACE))) {
167+
if ($this->nodeTypeResolver->isObjectTypes(
168+
$param->type,
169+
[new ObjectType(SymfonyClass::USER_INTERFACE), new ObjectType('DateTimeInterface')]
170+
)) {
168171
continue;
169172
}
170173

0 commit comments

Comments
 (0)