forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter out implicit throw points from callables when `exceptions.impl…
…icitThrows: false` Co-authored-by: Ondrej Mirtes <ondrej@mirtes.cz>
- Loading branch information
1 parent
70a75f6
commit e956fad
Showing
4 changed files
with
80 additions
and
2 deletions.
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
37 changes: 37 additions & 0 deletions
37
tests/PHPStan/Analyser/ImmediatelyCalledFunctionWithoutImplicitThrowTest.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,37 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
use function array_merge; | ||
|
||
class ImmediatelyCalledFunctionWithoutImplicitThrowTest extends TypeInferenceTestCase | ||
{ | ||
|
||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/immediately-called-function-without-implicit-throw.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args, | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return array_merge( | ||
parent::getAdditionalConfigFiles(), | ||
[__DIR__ . '/data/immediately-called-function-without-implicit-throw.neon'], | ||
); | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
tests/PHPStan/Analyser/data/immediately-called-function-without-implicit-throw.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 |
30 changes: 30 additions & 0 deletions
30
tests/PHPStan/Analyser/data/immediately-called-function-without-implicit-throw.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,30 @@ | ||
<?php | ||
|
||
namespace ImmediatelyCalledFunctionWithoutImplicitThrow; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use function PHPStan\Testing\assertVariableCertainty; | ||
|
||
try { | ||
$result = array_map('ucfirst', []); | ||
} finally { | ||
assertVariableCertainty(TrinaryLogic::createYes(), $result); | ||
} | ||
|
||
class SomeClass | ||
{ | ||
|
||
public function noThrow(): void | ||
{ | ||
} | ||
|
||
public function testFirstClassCallableNoThrow(): void | ||
{ | ||
try { | ||
$result = array_map($this->noThrow(...), []); | ||
} finally { | ||
assertVariableCertainty(TrinaryLogic::createYes(), $result); | ||
} | ||
} | ||
|
||
} |