Skip to content

Commit

Permalink
Merge pull request #25 from DaveLiddament/fix/must-use-result-with-pa…
Browse files Browse the repository at this point in the history
…rent-and-self

FIX MustUseResult with parent and self
  • Loading branch information
DaveLiddament authored Aug 13, 2024
2 parents 083f566 + bc2ab8b commit 1aa26fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Rules/MustUseResultRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$className = $scope->resolveName($class);

$classReflections = [
$this->reflectionProvider->getClass($class->toCodeString()),
$this->reflectionProvider->getClass($className),
];
} else {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PHPStan\Rules\Rule;

/** @extends AbstractRuleTestCase<MustUseResultRule> */
final class MustUseResultOnMethodTest extends AbstractRuleTestCase
final class MustUseResultTest extends AbstractRuleTestCase
{
protected function getRule(): Rule
{
Expand All @@ -30,6 +30,11 @@ public function testMustUseResultRuleOnStaticMethod(): void
);
}

public function testMustUseWithParent(): void
{
$this->assertIssuesReported(__DIR__.'/data/mustUseResult/mustUseResultWithParent.php');
}

protected function getErrorFormatter(): string
{
return 'Result returned by method must be used';
Expand Down
26 changes: 26 additions & 0 deletions tests/Rules/data/mustUseResult/mustUseResultWithParent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace MustUseResultWithParent {


use DaveLiddament\PhpLanguageExtensions\MustUseResult;


class Shape
{

public function __construct(
) {
}
}


class Circle extends Shape
{

public function __construct(
) {
parent::__construct();
}
}
}

0 comments on commit 1aa26fa

Please sign in to comment.