Skip to content

Check exceptions with PHPStan #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"require-dev": {
"nette/tester": "^2.5.4",
"phpstan/phpstan": "^2.1.12",
"phpstan/phpstan-strict-rules": "^2.0.4",
"spaze/phpstan-disallowed-calls": "^4.5.0",
"tracy/tracy": "^2.10.9"
},
Expand Down
50 changes: 49 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ parameters:
count: 1
path: src/GrammarProcessing/LexicalGrammar.php

-
message: '#^Only numeric types are allowed in \-, int\|false given on the right side\.$#'
identifier: minus.rightNonNumeric
count: 1
path: src/GrammarProcessing/LocationGetter.php

-
message: '#^Parameter \$column of class Vojtechdobes\\GrammarProcessing\\Location constructor expects int\<0, max\>, int given\.$#'
identifier: argument.type
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/spaze/phpstan-disallowed-calls/extension.neon

parameters:
checkMissingCallableSignature: true
disallowedFunctionCalls:
- function:
- 'dump()'
- 'var_dump()'
message: 'avoid committing debug calls'

exceptions:
check:
missingCheckedExceptionInThrows: true
tooWideThrowType: true

uncheckedExceptionClasses:
- LogicException

level: 8
paths:
- src
Expand Down
4 changes: 4 additions & 0 deletions src/GrammarProcessing/Ebnf/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function __construct(



/**
* @throws GrammarProcessing\CannotConsumeTokenException
* @throws GrammarProcessing\UnexpectedTokenException
*/
public function parseGrammarFromSource(string $source): GrammarProcessing\Grammar
{
return $this->parseGrammarFromAbstractSyntaxTree(
Expand Down
4 changes: 4 additions & 0 deletions src/GrammarProcessing/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function __construct(



/**
* @throws UnexpectedTokenException
*/
public function tokenizeSource(string $source): TokenStream
{
return $this->lexicalGrammar->parseSource($source);
Expand All @@ -55,6 +58,7 @@ public function tokenizeSource(string $source): TokenStream
* @param TRootSymbol $rootSymbol
* @return AbstractSyntaxTree<TRootSymbol>
* @throws CannotConsumeTokenException
* @throws UnexpectedTokenException
*/
public function parseSource(string $source, string $rootSymbol): AbstractSyntaxTree
{
Expand Down
3 changes: 3 additions & 0 deletions src/GrammarProcessing/TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public function consumeTokenWithType(string $type): Token



/**
* @throws CannotConsumeTokenException
*/
public function consumeTokenWithValue(string $value): Token
{
if (isset($this->tokens[$this->currentToken]) === FALSE) {
Expand Down
1 change: 1 addition & 0 deletions src/GrammarProcessing/Vocabulary/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function getPattern(array $nonterminals): string;

/**
* @param array<string, Symbol> $nonterminals
* @throws GrammarProcessing\CannotConsumeTokenException
*/
function acceptNode(
GrammarProcessing\Error $error,
Expand Down