Skip to content

Commit 40d93a1

Browse files
committed
missingCheckedExceptionInThrows: true
1 parent 810e504 commit 40d93a1

10 files changed

Lines changed: 45 additions & 8 deletions

File tree

build/phpstan.neon

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ parameters:
3434
- ../tests/PHPStan/Command/IgnoredRegexValidatorTest.php
3535
- ../src/Command/IgnoredRegexValidator.php
3636
exceptions:
37+
uncheckedExceptionRegexes:
38+
- '~^Exception$~'
3739
uncheckedExceptionClasses:
3840
- 'PHPStan\ShouldNotHappenException'
3941
- 'Symfony\Component\Console\Exception\InvalidArgumentException'
@@ -44,8 +46,26 @@ parameters:
4446
- 'PHPStan\DependencyInjection\ParameterNotFoundException'
4547
- 'PHPStan\Analyser\UndefinedVariableException'
4648
- 'RuntimeException'
49+
- 'Nette\Neon\Exception'
50+
- 'Nette\Utils\JsonException'
51+
- 'PHPStan\File\CouldNotReadFileException'
52+
- 'PHPStan\File\CouldNotWriteFileException'
53+
- 'PHPStan\Parser\ParserErrorsException'
54+
- 'ReflectionException'
55+
- 'Nette\Utils\AssertionException'
56+
- 'PHPStan\File\PathNotFoundException'
57+
- 'PHPStan\Broker\ClassNotFoundException'
58+
- 'PHPStan\Broker\FunctionNotFoundException'
59+
- 'PHPStan\Broker\ConstantNotFoundException'
60+
- 'PHPStan\Reflection\MissingMethodFromReflectionException'
61+
- 'PHPStan\Reflection\MissingPropertyFromReflectionException'
62+
- 'PHPStan\Reflection\MissingConstantFromReflectionException'
63+
- 'PHPStan\Type\CircularTypeAliasDefinitionException'
64+
- 'PHPStan\Broker\ClassAutoloadingException'
65+
- 'LogicException'
66+
- 'TypeError'
4767
check:
48-
missingCheckedExceptionInThrows: false
68+
missingCheckedExceptionInThrows: true
4969
tooWideThrowType: true
5070
featureToggles:
5171
readComposerPhpVersion: false

src/Command/FixerApplication.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ public function log(string $message): void
268268
return 0;
269269
}
270270

271+
/**
272+
* @throws FixerProcessException
273+
*/
271274
private function getFixerProcess(OutputInterface $output, int $serverPort): Process
272275
{
273276
if (!@mkdir($this->fixerTmpDir, 0777) && !is_dir($this->fixerTmpDir)) {

src/Parser/Parser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ interface Parser
88
/**
99
* @param string $file path to a file to parse
1010
* @return \PhpParser\Node\Stmt[]
11+
* @throws \PHPStan\Parser\ParserErrorsException
1112
*/
1213
public function parseFile(string $file): array;
1314

1415
/**
1516
* @param string $sourceCode
1617
* @return \PhpParser\Node\Stmt[]
18+
* @throws \PHPStan\Parser\ParserErrorsException
1719
*/
1820
public function parseString(string $sourceCode): array;
1921

src/PhpDoc/PhpDocStringResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function resolve(string $phpDocString): PhpDocNode
2424
{
2525
$tokens = new TokenIterator($this->phpDocLexer->tokenize($phpDocString));
2626
$phpDocNode = $this->phpDocParser->parse($tokens);
27-
$tokens->consumeTokenType(Lexer::TOKEN_END);
27+
$tokens->consumeTokenType(Lexer::TOKEN_END); // @phpstan-ignore-line
2828

2929
return $phpDocNode;
3030
}

src/PhpDoc/TypeStringResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function resolve(string $typeString, ?NameScope $nameScope = null): Type
2828
{
2929
$tokens = new TokenIterator($this->typeLexer->tokenize($typeString));
3030
$typeNode = $this->typeParser->parse($tokens);
31-
$tokens->consumeTokenType(Lexer::TOKEN_END);
31+
$tokens->consumeTokenType(Lexer::TOKEN_END); // @phpstan-ignore-line
3232

3333
return $this->typeNodeResolver->resolve($typeNode, $nameScope ?? new NameScope(null, []));
3434
}

src/Reflection/BetterReflection/SourceLocator/FileReadTrapStreamWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function stream_stat()
160160
public function url_stat($path, $flags)
161161
{
162162
if (self::$registeredStreamWrapperProtocols === null) {
163-
throw new \LogicException(self::class . ' not registered: cannot operate. Do not call this method directly.');
163+
throw new \PHPStan\ShouldNotHappenException(self::class . ' not registered: cannot operate. Do not call this method directly.');
164164
}
165165

166166
foreach (self::$registeredStreamWrapperProtocols as $protocol) {

src/Testing/ErrorFormatterTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function getOutputContent(): string
6161
protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors): AnalysisResult
6262
{
6363
if ($numFileErrors > 4 || $numFileErrors < 0 || $numGenericErrors > 2 || $numGenericErrors < 0) {
64-
throw new \Exception();
64+
throw new \PHPStan\ShouldNotHappenException();
6565
}
6666

6767
$fileErrors = array_slice([

tests/PHPStan/Command/CommandHelperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ public function dataResolveRelativePaths(): array
233233
* @dataProvider dataResolveRelativePaths
234234
* @param string $configFile
235235
* @param array<string, string> $expectedParameters
236+
* @throws \PHPStan\Command\InceptionNotSuccessfulException
236237
*/
237238
public function testResolveRelativePaths(
238239
string $configFile,

tests/PHPStan/Tests/AssertionClass.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@
55
class AssertionClass
66
{
77

8+
/** @throws \PHPStan\Tests\AssertionException */
89
public function assertString(?string $arg): bool
910
{
1011
if ($arg === null) {
11-
throw new \Exception();
12+
throw new \PHPStan\Tests\AssertionException();
1213
}
1314
return true;
1415
}
1516

17+
/** @throws AssertionException */
1618
public static function assertInt(?int $arg): bool
1719
{
1820
if ($arg === null) {
19-
throw new \Exception();
21+
throw new \PHPStan\Tests\AssertionException();
2022
}
2123
return true;
2224
}
2325

2426
/**
2527
* @param mixed $arg
2628
* @return bool
29+
* @throws AssertionException
2730
*/
2831
public function assertNotInt($arg): bool
2932
{
3033
if (is_int($arg)) {
31-
throw new \Exception();
34+
throw new \PHPStan\Tests\AssertionException();
3235
}
3336

3437
return true;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Tests;
4+
5+
class AssertionException extends \Exception
6+
{
7+
8+
}

0 commit comments

Comments
 (0)