Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle throws void #123

Merged
merged 1 commit into from
May 28, 2020
Merged
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
2 changes: 1 addition & 1 deletion src/Rules/ThrowsPhpDocInheritanceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function processNode(Node $node, Scope $scope): array
$parentThrowType = $methodReflection->getThrowType();
}

if ($parentThrowType === null) {
if ($parentThrowType === null || $parentThrowType instanceof VoidType) {
$messages[] = sprintf(
'PHPDoc tag @throws with type %s is not compatible with parent',
$throwType->describe(VerbosityLevel::typeOnly())
Expand Down
18 changes: 18 additions & 0 deletions tests/src/Rules/data/throws-inheritance-interfaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function __construct();

public function parentWithoutThrows(): void;

/**
* @throws void
*/
public function parentWithThrowsVoid(): void;

}

interface ThrowsAnnotations extends BaseThrowsAnnotations
Expand All @@ -49,6 +54,11 @@ public function __construct();
*/
public function parentWithoutThrows(): void; // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent

/**
* @throws BaseException
*/
public function parentWithThrowsVoid(): void; // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent

}

class Implementation implements BaseThrowsAnnotations
Expand Down Expand Up @@ -86,4 +96,12 @@ public function parentWithoutThrows(): void // error: PHPDoc tag @throws with ty

}

/**
* @throws BaseException
*/
public function parentWithThrowsVoid(): void // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent
{

}

}