Skip to content

Commit f90e1f0

Browse files
Merge pull request #9 from vojtech-dobes/check-exceptions
Check exceptions with PHPStan
2 parents 7243f25 + 4f46601 commit f90e1f0

File tree

8 files changed

+78
-1
lines changed

8 files changed

+78
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"require-dev": {
3636
"nette/tester": "^2.5.4",
3737
"phpstan/phpstan": "^2.1.12",
38+
"phpstan/phpstan-strict-rules": "^2.0.4",
3839
"spaze/phpstan-disallowed-calls": "^4.5.0",
3940
"tracy/tracy": "^2.10.9"
4041
},

composer.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ parameters:
2424
count: 1
2525
path: src/GrammarProcessing/LexicalGrammar.php
2626

27+
-
28+
message: '#^Only numeric types are allowed in \-, int\|false given on the right side\.$#'
29+
identifier: minus.rightNonNumeric
30+
count: 1
31+
path: src/GrammarProcessing/LocationGetter.php
32+
2733
-
2834
message: '#^Parameter \$column of class Vojtechdobes\\GrammarProcessing\\Location constructor expects int\<0, max\>, int given\.$#'
2935
identifier: argument.type

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
includes:
22
- phpstan-baseline.neon
3+
- vendor/phpstan/phpstan-strict-rules/rules.neon
34
- vendor/spaze/phpstan-disallowed-calls/extension.neon
45

56
parameters:
7+
checkMissingCallableSignature: true
68
disallowedFunctionCalls:
79
- function:
810
- 'dump()'
911
- 'var_dump()'
1012
message: 'avoid committing debug calls'
1113

14+
exceptions:
15+
check:
16+
missingCheckedExceptionInThrows: true
17+
tooWideThrowType: true
18+
19+
uncheckedExceptionClasses:
20+
- LogicException
21+
1222
level: 8
1323
paths:
1424
- src

src/GrammarProcessing/Ebnf/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function __construct(
3737

3838

3939

40+
/**
41+
* @throws GrammarProcessing\CannotConsumeTokenException
42+
* @throws GrammarProcessing\UnexpectedTokenException
43+
*/
4044
public function parseGrammarFromSource(string $source): GrammarProcessing\Grammar
4145
{
4246
return $this->parseGrammarFromAbstractSyntaxTree(

src/GrammarProcessing/Grammar.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function __construct(
4343

4444

4545

46+
/**
47+
* @throws UnexpectedTokenException
48+
*/
4649
public function tokenizeSource(string $source): TokenStream
4750
{
4851
return $this->lexicalGrammar->parseSource($source);
@@ -55,6 +58,7 @@ public function tokenizeSource(string $source): TokenStream
5558
* @param TRootSymbol $rootSymbol
5659
* @return AbstractSyntaxTree<TRootSymbol>
5760
* @throws CannotConsumeTokenException
61+
* @throws UnexpectedTokenException
5862
*/
5963
public function parseSource(string $source, string $rootSymbol): AbstractSyntaxTree
6064
{

src/GrammarProcessing/TokenStream.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public function consumeTokenWithType(string $type): Token
102102

103103

104104

105+
/**
106+
* @throws CannotConsumeTokenException
107+
*/
105108
public function consumeTokenWithValue(string $value): Token
106109
{
107110
if (isset($this->tokens[$this->currentToken]) === FALSE) {

src/GrammarProcessing/Vocabulary/Symbol.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function getPattern(array $nonterminals): string;
1717

1818
/**
1919
* @param array<string, Symbol> $nonterminals
20+
* @throws GrammarProcessing\CannotConsumeTokenException
2021
*/
2122
function acceptNode(
2223
GrammarProcessing\Error $error,

0 commit comments

Comments
 (0)