Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Rules/Playground/MethodNeverRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function processNode(Node $node, Scope $scope): array

$method = $node->getMethodReflection();

if (!$method->isPrivate() && !$node->getClassReflection()->isFinal()) {
return [];
}

$returnType = $method->getReturnType();
$helperResult = $this->helper->shouldReturnNever($node, $returnType);
if ($helperResult === false) {
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Rules/Playground/MethodNeverRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ public function testRule(): void
]);
}

public function testBug10820(): void
{
$this->analyse([__DIR__ . '/data/bug-10820.php'], [
[
'Method Bug10820\NonFinalBase::doPrivate() always throws an exception, it should have return type "never".',
28,
],
[
'Method Bug10820\FinalClass::doSomething() always throws an exception, it should have return type "never".',
36,
],
]);
}

}
40 changes: 40 additions & 0 deletions tests/PHPStan/Rules/Playground/data/bug-10820.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types = 1);

namespace Bug10820;

abstract class Value
{
public function assertString(): SassString
{
throw new \Exception('this is not a string');
}
}

final class SassString extends Value
{
public function assertString(): SassString
{
return $this;
}
}

class NonFinalBase
{
protected function doSomething(): int
{
throw new \Exception('not implemented');
}

private function doPrivate(): int
{
throw new \Exception('not implemented');
}
}

final class FinalClass
{
public function doSomething(): int
{
throw new \Exception('not implemented');
}
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Playground/data/method-never.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MethodNever;

class Foo
final class Foo
{

public function doFoo(): never
Expand Down
Loading