Skip to content
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

Add PHPStan to QA checks #2355

Merged
merged 1 commit into from
Aug 18, 2023
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 .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/.codecov.yml export-ignore
/.phpcs.xml.dist export-ignore
/CODE_OF_CONDUCT.md export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/.github export-ignore
/Tests export-ignore
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/basic-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,31 @@ jobs:
- name: Fail the build on fixer conflicts and other errors
if: ${{ steps.phpcbf.outputs.EXITCODE != 0 && steps.phpcbf.outputs.EXITCODE != 1 }}
run: exit ${{ steps.phpcbf.outputs.EXITCODE }}

phpstan:
name: "PHPStan"

runs-on: "ubuntu-latest"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: phpstan

# Install dependencies and handle caching in one go.
# Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Run PHPStan
run: phpstan analyse
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/
phpunit.xml
phpcs.xml
.phpcs.xml
phpstan.neon
26 changes: 26 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameters:
#phpVersion: 50400 # Needs to be 70100 or higher... sigh...
level: 5
paths:
- WordPress
bootstrapFiles:
- Tests/bootstrap.php
treatPhpDocTypesAsCertain: false

ignoreErrors:
# Level 0
- '#^Result of method \S+ \(void\) is used\.$#'

# Level 4
- '#^Property \S+::\$\S+ \([^)]+\) in isset\(\) is not nullable\.$#'
-
count: 1
message: '#^Result of && is always true\.$#'
path: WordPress/Sniffs/Security/EscapeOutputSniff.php
-
count: 1
message: '#^Strict comparison using === between true and false will always evaluate to false\.$#'
path: WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php

# Level 5
- '#^Parameter \#3 \$value of method \S+File::recordMetric\(\) expects string, \(?(float|int|bool)(\|(float|int|bool))*\)? given\.$#'
Loading