Skip to content

Commit 5f505da

Browse files
authored
Merge pull request #267 from PHPCSStandards/feature/add-phpstan
Add PHPStan to QA checks
2 parents 431d42b + 46d4a05 commit 5f505da

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
.remarkrc export-ignore
1313
.yamllint.yml export-ignore
1414
phpcs.xml.dist export-ignore
15+
phpstan.neon.dist export-ignore
1516
phpunit.xml.dist export-ignore
1617
phpunit-bootstrap.php export-ignore
1718
/.github/ export-ignore

.github/workflows/basics.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ jobs:
9595
- name: Check sniff feature completeness
9696
run: composer check-complete
9797

98+
phpstan:
99+
name: "PHPStan"
100+
runs-on: "ubuntu-latest"
101+
102+
steps:
103+
- name: Checkout code
104+
uses: actions/checkout@v3
105+
106+
- name: Install PHP
107+
uses: shivammathur/setup-php@v2
108+
with:
109+
php-version: '7.4'
110+
coverage: none
111+
tools: phpstan
112+
113+
# Install dependencies and handle caching in one go.
114+
# Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized.
115+
# @link https://github.com/marketplace/actions/install-composer-dependencies
116+
- name: Install Composer dependencies
117+
uses: "ramsey/composer-install@v2"
118+
with:
119+
# Bust the cache at least once a month - output format: YYYY-MM.
120+
custom-cache-suffix: $(date -u "+%Y-%m")
121+
122+
- name: Run PHPStan
123+
run: phpstan analyse
124+
98125
remark:
99126
name: 'QA Markdown'
100127
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
/phpcs.xml
66
/phpunit.xml
77
/.phpunit.result.cache
8+
phpstan.neon

phpstan.neon.dist

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
parameters:
2+
#phpVersion: 50400 # Needs to be 70100 or higher... sigh...
3+
level: 6
4+
paths:
5+
- Modernize
6+
- NormalizedArrays
7+
- Universal
8+
bootstrapFiles:
9+
- phpunit-bootstrap.php
10+
treatPhpDocTypesAsCertain: false
11+
12+
ignoreErrors:
13+
# Level 1
14+
# Keep to stay in line with parent class.
15+
-
16+
message: '`^Constructor of class PHPCSExtra\\Universal\\Helpers\\DummyTokenizer has an unused parameter \$content\.$`'
17+
path: Universal\Helpers\DummyTokenizer.php
18+
count: 1
19+
20+
# Level 4
21+
# PHPStan doesn't seem to like uninitialized properties...
22+
-
23+
message: '`^Property \S+Sniff::\$(phpVersion|tabWidth) \(int\) in isset\(\) is not nullable\.$`'
24+
paths:
25+
- Modernize\Sniffs\FunctionCalls\DirnameSniff.php
26+
- Universal\Sniffs\Arrays\DuplicateArrayKeySniff.php
27+
- Universal\Sniffs\CodeAnalysis\ConstructorDestructorReturnSniff.php
28+
- Universal\Sniffs\WhiteSpace\CommaSpacingSniff.php
29+
- Universal\Sniffs\WhiteSpace\DisallowInlineTabsSniff.php
30+
- Universal\Sniffs\WhiteSpace\PrecisionAlignmentSniff.php
31+
-
32+
message: '`^Strict comparison using === between true and false will always evaluate to false\.$`'
33+
paths:
34+
- Modernize\Sniffs\FunctionCalls\DirnameSniff.php
35+
- Universal\Sniffs\Arrays\DuplicateArrayKeySniff.php
36+
- Universal\Sniffs\CodeAnalysis\ConstructorDestructorReturnSniff.php
37+
- Universal\Sniffs\WhiteSpace\CommaSpacingSniff.php
38+
- Universal\Sniffs\WhiteSpace\DisallowInlineTabsSniff.php
39+
- Universal\Sniffs\WhiteSpace\PrecisionAlignmentSniff.php
40+
-
41+
message: '`^Property PHPCSExtra\\Universal\\Sniffs\\Arrays\\DuplicateArrayKeySniff\:\:\$currentMaxIntKey[GL]t8 \(int\) in isset\(\) is not nullable\.$`'
42+
path: Universal\Sniffs\Arrays\DuplicateArrayKeySniff.php
43+
count: 5
44+
-
45+
message: '`^Result of && is always false\.$`'
46+
path: Universal\Sniffs\Arrays\DuplicateArrayKeySniff.php
47+
count: 1
48+
49+
# Level 5
50+
# We're not using strict types, so this will be juggled without any issues.
51+
- '#^Parameter \#3 \$value of method \S+File::recordMetric\(\) expects string, \(?(float|int|bool)(<[^>]+>)?(\|(float|int|bool)(<[^>]+>)?)*\)? given\.$#'
52+
- '#^Parameter \#2 \$content of method \S+Fixer::replaceToken\(\) expects string, \(?(float|int|bool)(<[^>]+>)?(\|(float|int|bool)(<[^>]+>)?)*\)? given\.$#'

0 commit comments

Comments
 (0)