Skip to content

Commit

Permalink
Do not require return type for renamed trait constructor [close #23] (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciki authored Oct 19, 2023
1 parent 65cd7bc commit ff88cf5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Collectors/ReturnTypeDeclarationCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public function processNode(Node $node, Scope $scope): ?array
return null;
}

if ($scope->isInTrait()) {
$originalMethodName = $node->getAttribute('originalTraitMethodName');
if ($originalMethodName === '__construct') {
return null;
}
}

$missingTypeLines = [];

if (! $node->returnType instanceof Node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace TomasVotruba\TypeCoverage\Tests\Rules\ReturnTypeCoverageRule\Fixture;

final class SkipTraitConstructor
{
use TraitWithConstructor {
TraitWithConstructor::__construct as traitConstruct;
}

public function __construct()
{
$this->traitConstruct();
}
}

trait TraitWithConstructor
{
public function __construct()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static function provideData(): Iterator
{
yield [[__DIR__ . '/Fixture/SkipKnownReturnType.php', __DIR__ . '/Fixture/SkipAgainKnownReturnType.php'], []];
yield [[__DIR__ . '/Fixture/SkipConstructor.php'], []];
yield [[__DIR__ . '/Fixture/SkipTraitConstructor.php'], []];

$errorMessage = sprintf(ReturnTypeCoverageRule::ERROR_MESSAGE, 2, 0, 0, 80);
yield [[__DIR__ . '/Fixture/UnknownReturnType.php'], [[$errorMessage, 9], [$errorMessage, 13]]];
Expand Down

0 comments on commit ff88cf5

Please sign in to comment.