-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch refs/heads/1.10.x into 1.11.x
- Loading branch information
Showing
4 changed files
with
67 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
38 changes: 38 additions & 0 deletions
38
tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php
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,38 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Exceptions; | ||
|
||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
use function array_merge; | ||
|
||
/** | ||
* @extends RuleTestCase<CatchWithUnthrownExceptionRule> | ||
*/ | ||
class AbilityToDisableImplicitThrowsTest extends RuleTestCase | ||
{ | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return new CatchWithUnthrownExceptionRule(); | ||
} | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/ability-to-disable-implicit-throws.php'], [ | ||
[ | ||
'Dead catch - Throwable is never thrown in the try block.', | ||
17, | ||
], | ||
]); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return array_merge( | ||
parent::getAdditionalConfigFiles(), | ||
[__DIR__ . '/data/ability-to-disable-implicit-throws.neon'], | ||
); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
tests/PHPStan/Rules/Exceptions/data/ability-to-disable-implicit-throws.neon
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,3 @@ | ||
parameters: | ||
exceptions: | ||
implicitThrows: false |
25 changes: 25 additions & 0 deletions
25
tests/PHPStan/Rules/Exceptions/data/ability-to-disable-implicit-throws.php
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,25 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace AbilityToDisableImplicitThrows; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(callable $c): void | ||
{ | ||
try { | ||
$c(); | ||
} catch (\Throwable $e) { // no error here | ||
|
||
} | ||
|
||
try { | ||
$this->method(); | ||
} catch (\Throwable $e) { // Dead catch - Throwable is never thrown in the try block. | ||
|
||
} | ||
} | ||
|
||
public function method(): void | ||
{ | ||
} | ||
} |