Skip to content
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/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
{
}
}