Skip to content

Commit c359234

Browse files
committed
Refactor phpstan config files to support multiple php versions
1 parent 5a355bf commit c359234

File tree

6 files changed

+78
-31
lines changed

6 files changed

+78
-31
lines changed

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
run: composer install -n --prefer-dist
3434

3535
- name: Run PHPStan
36-
run: ./vendor/bin/phpstan analyse src
36+
run: ./vendor/bin/phpstan analyse src -c phpstan.${{ matrix.php }}.neon

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ phpcbf:
6666
PHP_VERSION=7.4 $(PHP_CS_FIXER)
6767

6868
phpstan: vendor
69-
$(EXEC_PHP) vendor/bin/phpstan analyse src -c phpstan.neon -a vendor/autoload.php
69+
$(EXEC_PHP) vendor/bin/phpstan analyse src -c phpstan.$(PHP_VERSION).neon -a vendor/autoload.php
7070

71-
phpstan: vendor
72-
$(EXEC_PHP) vendor/bin/phpstan analyse src -c phpstan.neon -a vendor/autoload.php
71+
phpstan-all-php-versions:
72+
PHP_VERSION=7.4 make phpstan
73+
PHP_VERSION=8.1 make phpstan
7374

7475
phpstan-baseline: vendor
75-
$(EXEC_PHP) vendor/bin/phpstan analyse src -c phpstan.neon -a vendor/autoload.php --generate-baseline
76+
$(EXEC_PHP) vendor/bin/phpstan analyse src -c phpstan.$(PHP_VERSION).neon -a vendor/autoload.php --generate-baseline
7677

7778
infection: vendor
7879
$(EXEC_PHP) vendor/bin/phpunit --coverage-xml=build/coverage/coverage-xml --log-junit=build/coverage/phpunit.junit.xml

phpstan.neon renamed to phpstan.7.4.neon

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
includes:
2-
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
3-
- vendor/phpstan/phpstan-strict-rules/rules.neon
4-
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
5-
- vendor/phpstan/phpstan-phpunit/extension.neon
2+
- phpstan.base.neon
63

74
parameters:
8-
level: max
9-
10-
# Some errors ignored are specific to a php version so they're reported as unmatched when phpstan is ran with a
11-
# different php version
12-
reportUnmatchedIgnoredErrors: false
13-
14-
treatPhpDocTypesAsCertain: false
155
ignoreErrors:
16-
# Missing strict comparison
17-
- '#^Construct empty\(\) is not allowed. Use more strict comparison.$#'
18-
19-
# thecodingmachine/safe and thecodingmachine/phpstan-safe-rule don't support 8.1 Pspell
6+
# php 8.1 code
207
-
218
message: "#^Function pspell_config_create is unsafe to use\\. It can return FALSE instead of throwing an exception\\. Please add 'use function Safe\\\\pspell_config_create;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#"
229
count: 1
@@ -37,16 +24,6 @@ parameters:
3724
count: 1
3825
path: src/Spellchecker/PHPPspell.php
3926

40-
-
41-
message: "#^Parameter \\#1 \\$dictionary of function pspell_check expects int, int\\|false given\\.$#"
42-
count: 1
43-
path: src/Spellchecker/PHPPspell.php
44-
45-
-
46-
message: "#^Parameter \\#1 \\$dictionary of function pspell_suggest expects int, int\\|false given\\.$#"
47-
count: 1
48-
path: src/Spellchecker/PHPPspell.php
49-
5027
-
5128
message: "#^Parameter \\#1 \\$conf of function pspell_config_ignore expects int, int\\|false given\\.$#"
5229
count: 1
@@ -71,3 +48,9 @@ parameters:
7148
message: "#^Parameter \\#1 \\$pspell of function pspell_suggest expects int, int\\|false given\\.$#"
7249
count: 1
7350
path: src/Spellchecker/PHPPspell.php
51+
52+
# preg_match_all can be null in php >8
53+
-
54+
message: "#^Casting to int something that's already int\\.$#"
55+
count: 1
56+
path: src/Utils/LineAndOffset.php

phpstan.8.1.neon

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
includes:
2+
- phpstan.base.neon
3+
4+
parameters:
5+
ignoreErrors:
6+
-
7+
message: "#^Function pspell_config_create is unsafe to use\\. It can return FALSE instead of throwing an exception\\. Please add 'use function Safe\\\\pspell_config_create;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#"
8+
count: 1
9+
path: src/Spellchecker/PHPPspell.php
10+
11+
-
12+
message: "#^Function pspell_config_ignore is unsafe to use\\. It can return FALSE instead of throwing an exception\\. Please add 'use function Safe\\\\pspell_config_ignore;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#"
13+
count: 1
14+
path: src/Spellchecker/PHPPspell.php
15+
16+
-
17+
message: "#^Function pspell_config_mode is unsafe to use\\. It can return FALSE instead of throwing an exception\\. Please add 'use function Safe\\\\pspell_config_mode;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#"
18+
count: 1
19+
path: src/Spellchecker/PHPPspell.php
20+
21+
-
22+
message: "#^Function pspell_new_config is unsafe to use\\. It can return FALSE instead of throwing an exception\\. Please add 'use function Safe\\\\pspell_new_config;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library\\.$#"
23+
count: 1
24+
path: src/Spellchecker/PHPPspell.php
25+
26+
-
27+
message: "#^Parameter \\#1 \\$dictionary of function pspell_check expects PSpell\\\\Dictionary, PSpell\\\\Dictionary\\|false given\\.$#"
28+
count: 1
29+
path: src/Spellchecker/PHPPspell.php
30+
31+
-
32+
message: "#^Parameter \\#1 \\$dictionary of function pspell_check expects PSpell\\\\Dictionary, int given\\.$#"
33+
count: 1
34+
path: src/Spellchecker/PHPPspell.php
35+
36+
-
37+
message: "#^Parameter \\#1 \\$dictionary of function pspell_suggest expects PSpell\\\\Dictionary, PSpell\\\\Dictionary\\|false given\\.$#"
38+
count: 1
39+
path: src/Spellchecker/PHPPspell.php
40+
41+
-
42+
message: "#^Parameter \\#1 \\$dictionary of function pspell_suggest expects PSpell\\\\Dictionary, int given\\.$#"
43+
count: 1
44+
path: src/Spellchecker/PHPPspell.php

phpstan.base.neon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
includes:
2+
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
3+
- vendor/phpstan/phpstan-strict-rules/rules.neon
4+
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
5+
- vendor/phpstan/phpstan-phpunit/extension.neon
6+
7+
parameters:
8+
level: max
9+
10+
treatPhpDocTypesAsCertain: false
11+
ignoreErrors:
12+
# Missing strict comparison
13+
- '#^Construct empty\(\) is not allowed. Use more strict comparison.$#'
14+
15+
# function_exists call
16+
-
17+
message: "#^Class PhpSpellcheck\\\\t not found\\.$#"
18+
count: 1
19+
path: src/Text/functions.php

src/Utils/LineAndOffset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function findFromFirstCharacterOffset(string $text, int $offsetFro
3131
}
3232

3333
$textBeforeOffset = mb_substr($text, 0, $offsetFromFirstCharacter);
34-
$line = \Safe\preg_match_all('/\R/u', $textBeforeOffset, $matches) + 1;
34+
$line = ((int) \Safe\preg_match_all('/\R/u', $textBeforeOffset, $matches)) + 1;
3535
$offsetOfPreviousLinebreak = mb_strrpos($textBeforeOffset, PHP_EOL, 0);
3636

3737
$offset = $offsetFromFirstCharacter - ($offsetOfPreviousLinebreak !== false ? $offsetOfPreviousLinebreak + 1 : 0);

0 commit comments

Comments
 (0)