Skip to content

Commit

Permalink
Merge branch refs/heads/1.10.x into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot authored Aug 18, 2023
2 parents a719f09 + c016c53 commit 98908c9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Testing/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function getAnalyser(): Analyser
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
[],
[],
true,
self::getContainer()->getParameter('exceptions')['implicitThrows'],
$this->shouldTreatPhpDocTypesAsCertain(),
self::getContainer()->getParameter('featureToggles')['detectDeadTypeInMultiCatch'],
);
Expand Down
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'],
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
exceptions:
implicitThrows: false
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
{
}
}

0 comments on commit 98908c9

Please sign in to comment.