diff --git a/composer.json b/composer.json index ebc2bb4..3d7f02a 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/composer.lock b/composer.lock index 379cc00..587c714 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "aea19a6b932b3ab92ec26d21f5e10b70", + "content-hash": "e5b5acae37b59710218e5b85a6e9bd7b", "packages": [], "packages-dev": [ { @@ -140,6 +140,54 @@ ], "time": "2025-04-16T13:19:18+00:00" }, + { + "name": "phpstan/phpstan-strict-rules", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-strict-rules.git", + "reference": "3e139cbe67fafa3588e1dbe27ca50f31fdb6236a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/3e139cbe67fafa3588e1dbe27ca50f31fdb6236a", + "reference": "3e139cbe67fafa3588e1dbe27ca50f31fdb6236a", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0.4" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Extra strict and opinionated rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.0.4" + }, + "time": "2025-03-18T11:42:40+00:00" + }, { "name": "spaze/phpstan-disallowed-calls", "version": "v4.5.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b1a5ba7..01487cf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/phpstan.neon b/phpstan.neon index 8d70467..f63e137 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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 diff --git a/src/GrammarProcessing/Ebnf/Parser.php b/src/GrammarProcessing/Ebnf/Parser.php index 634880c..e1859b0 100644 --- a/src/GrammarProcessing/Ebnf/Parser.php +++ b/src/GrammarProcessing/Ebnf/Parser.php @@ -37,6 +37,10 @@ public function __construct( + /** + * @throws GrammarProcessing\CannotConsumeTokenException + * @throws GrammarProcessing\UnexpectedTokenException + */ public function parseGrammarFromSource(string $source): GrammarProcessing\Grammar { return $this->parseGrammarFromAbstractSyntaxTree( diff --git a/src/GrammarProcessing/Grammar.php b/src/GrammarProcessing/Grammar.php index 78a504a..c3a5e5d 100644 --- a/src/GrammarProcessing/Grammar.php +++ b/src/GrammarProcessing/Grammar.php @@ -43,6 +43,9 @@ public function __construct( + /** + * @throws UnexpectedTokenException + */ public function tokenizeSource(string $source): TokenStream { return $this->lexicalGrammar->parseSource($source); @@ -55,6 +58,7 @@ public function tokenizeSource(string $source): TokenStream * @param TRootSymbol $rootSymbol * @return AbstractSyntaxTree * @throws CannotConsumeTokenException + * @throws UnexpectedTokenException */ public function parseSource(string $source, string $rootSymbol): AbstractSyntaxTree { diff --git a/src/GrammarProcessing/TokenStream.php b/src/GrammarProcessing/TokenStream.php index 76f34b0..2203bc9 100644 --- a/src/GrammarProcessing/TokenStream.php +++ b/src/GrammarProcessing/TokenStream.php @@ -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) { diff --git a/src/GrammarProcessing/Vocabulary/Symbol.php b/src/GrammarProcessing/Vocabulary/Symbol.php index 7696e0a..d0ced16 100644 --- a/src/GrammarProcessing/Vocabulary/Symbol.php +++ b/src/GrammarProcessing/Vocabulary/Symbol.php @@ -17,6 +17,7 @@ function getPattern(array $nonterminals): string; /** * @param array $nonterminals + * @throws GrammarProcessing\CannotConsumeTokenException */ function acceptNode( GrammarProcessing\Error $error,