Skip to content

Commit

Permalink
NoParamTypeRemovalRule: Skip constructors (rectorphp#37)
Browse files Browse the repository at this point in the history
* NoParamTypeRemovalRule: Skip constructors

* Update SkipConstruct.php
  • Loading branch information
staabm authored Jul 9, 2024
1 parent 7a96f32 commit 59124fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Rules/NoParamTypeRemovalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function processNode(Node $node, Scope $scope): array
}

$classMethodName = (string) $node->name;
if ($classMethodName === '__construct') {
return [];
}

$parentClassMethodReflection = $this->methodNodeAnalyser->matchFirstParentClassMethod($scope, $classMethodName);
if (! $parentClassMethodReflection instanceof PhpMethodReflection) {
return [];
Expand Down
20 changes: 20 additions & 0 deletions tests/Rules/NoParamTypeRemovalRule/Fixture/SkipConstruct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Rector\TypePerfect\Tests\Rules\NoParamTypeRemovalRule\Fixture;

class SkipConstruct extends ParentConstructorClass
{
public function __construct($someArg, $someOther)
{
parent::__construct('foo', 4);
}
}

class ParentConstructorClass
{
public function __construct(string $string, int $int)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testRule(string $filePath, array $expectedErrorMessagesWithLines

public static function provideData(): Iterator
{
yield [__DIR__ . '/Fixture/SkipConstruct.php', []];
yield [__DIR__ . '/Fixture/SkipPhpDocType.php', []];
yield [__DIR__ . '/Fixture/SkipPresentType.php', []];
yield [__DIR__ . '/Fixture/SkipNoType.php', []];
Expand Down

0 comments on commit 59124fe

Please sign in to comment.