-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Expr Throw - PHP 8 * check:lint only with PHP 8.0 * fix phpstan check - instanceof PHPStan\Reflection\MethodReflection
- Loading branch information
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pepakriz\PHPStanExceptionRules\Rules\ExpressionThrows; | ||
|
||
use RuntimeException; | ||
|
||
class FooException extends RuntimeException | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self(); | ||
} | ||
} | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
function foo1() { | ||
$callable = fn() => throw new FooException(); | ||
} | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
function foo2() { | ||
return match (random_bytes(1)) { | ||
'a' => 'b', | ||
default => throw new FooException(), | ||
}; | ||
} | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
function foo3() { | ||
$value = $nullableValue ?? throw new FooException(); | ||
} | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
function foo4() { | ||
$value = $falsableValue ?: throw new FooException(); | ||
} | ||
|
||
|
||
class FutureThrows | ||
{ | ||
private ?string $name; | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
public function ok1(): string | ||
{ | ||
return $this->name ?? throw new FooException(); | ||
} | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
public function ok2(): string | ||
{ | ||
return $this->name ?? $this->ok2(); | ||
} | ||
|
||
/** | ||
* @throws FooException | ||
*/ | ||
public function ok3(): string | ||
{ | ||
return $this->name ?? throw FooException::create(); | ||
} | ||
|
||
public function err(): string | ||
{ | ||
return $this->name ?? throw new FooException(); // error: Missing @throws Pepakriz\PHPStanExceptionRules\Rules\ExpressionThrows\FooException annotation | ||
} | ||
} |