-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Tests / Build Scripts: Configure PHPStan levels 1-6 [Exploratory] #7619
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
f7902b2
805199c
5aad07a
cc24e27
c2da5b6
8fd0517
cdc3c6d
9bb36a4
6744b39
64d5311
3746454
da39d35
52375af
004f70a
44c3beb
8a3775f
6589ce9
c2acb6e
44a62c0
0e2d031
d949a94
c92201e
d6d59a0
3a7f4d4
06f7f92
9ca376e
50169b6
fb61258
174afe0
c8645e8
fe5882a
5f43db2
0840486
8a152d3
9125d57
94fca70
87e966a
1c9cfb9
c43413f
7e71c2f
0069fc5
d5a10d2
f6af340
46d4e72
760d701
9680162
2839f28
a4ee081
6e2aa00
020f347
9f09845
86c9442
e50b2dc
8ea09de
0308f9e
5ccfa1c
79b737b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| name: PHPStan Static Analysis | ||
|
|
||
| on: | ||
| # PHPStan testing was introduced in @todo. | ||
| push: | ||
| branches: | ||
| - trunk | ||
| - '6.9' | ||
| - '[7-9].[0-9]' | ||
| tags: | ||
| - '6.9' | ||
| - '6.9.[0-9]+' | ||
| - '[7-9].[0-9]' | ||
| - '[7-9]+.[0-9].[0-9]+' | ||
| pull_request: | ||
| branches: | ||
| - trunk | ||
| - '6.9' | ||
| - '[7-9].[0-9]' | ||
| paths: | ||
| # This workflow only scans PHP files. | ||
| - '**.php' | ||
| # These files configure Composer. Changes could affect the outcome. | ||
| - 'composer.*' | ||
| # These files configure PHPStan. Changes could affect the outcome. | ||
| - 'phpstan.neon.dist' | ||
| - 'tests/phpstan/base.neon' | ||
| # Confirm any changes to relevant workflow files. | ||
| - '.github/workflows/php-static-analysis.yml' | ||
| - '.github/workflows/reusable-php-static-analysis.yml' | ||
| workflow_dispatch: | ||
|
|
||
| # Cancels all previous workflow runs for pull requests that have not completed. | ||
| concurrency: | ||
| # The concurrency group contains the workflow name and the branch name for pull requests | ||
| # or the commit hash for any other events. | ||
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} | ||
| cancel-in-progress: true | ||
|
|
||
| # Disable permissions for all available scopes by default. | ||
| # Any needed permissions should be configured at the job level. | ||
| permissions: {} | ||
|
|
||
| jobs: | ||
| # Runs PHPStan Static Analysis. | ||
| phpstan: | ||
| name: PHP coding standards | ||
| uses: ./.github/workflows/reusable-php-static-analysis.yml | ||
| permissions: | ||
| contents: read | ||
| if: ${{ github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' ) }} | ||
|
|
||
| slack-notifications: | ||
| name: Slack Notifications | ||
| uses: ./.github/workflows/slack-notifications.yml | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| needs: [ phpstan ] | ||
| if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} | ||
| with: | ||
| calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} | ||
| secrets: | ||
| SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} | ||
| SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} | ||
| SLACK_GHA_FIXED_WEBHOOK: ${{ secrets.SLACK_GHA_FIXED_WEBHOOK }} | ||
| SLACK_GHA_FAILURE_WEBHOOK: ${{ secrets.SLACK_GHA_FAILURE_WEBHOOK }} | ||
|
|
||
| failed-workflow: | ||
| name: Failed workflow tasks | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| actions: write | ||
| needs: [ slack-notifications ] | ||
| if: | | ||
| always() && | ||
| github.repository == 'WordPress/wordpress-develop' && | ||
| github.event_name != 'pull_request' && | ||
| github.run_attempt < 2 && | ||
| ( | ||
| contains( needs.*.result, 'cancelled' ) || | ||
| contains( needs.*.result, 'failure' ) | ||
| ) | ||
|
|
||
| steps: | ||
| - name: Dispatch workflow run | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| retries: 2 | ||
| retry-exempt-status-codes: 418 | ||
| script: | | ||
| github.rest.actions.createWorkflowDispatch({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: 'failed-workflow.yml', | ||
| ref: 'trunk', | ||
| inputs: { | ||
| run_id: `${context.runId}`, | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| ## | ||
| # A reusable workflow that runs PHP Static Analysis tests. | ||
| ## | ||
| name: PHP Static Analysis | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| php-version: | ||
| description: 'The PHP version to use.' | ||
| required: false | ||
| type: 'string' | ||
| default: 'latest' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking this is why CI fails despite passing locally - I've baselined on v8.3.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to leave out a default since this could cause issues in the future. For example, once 9.0 is the latest PHP, versions of WP that don't support it shouldn't have that as the default. Better to be explicit about the version.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, but what version do we use:
|
||
|
|
||
| # Disable permissions for all available scopes by default. | ||
| # Any needed permissions should be configured at the job level. | ||
| permissions: {} | ||
|
|
||
| jobs: | ||
| # Runs PHP static analysis tests. | ||
| # | ||
| # Violations are reported inline with annotations. | ||
| # | ||
| # Performs the following steps: | ||
| # - Checks out the repository. | ||
| # - Sets up PHP. | ||
| # - Logs debug information. | ||
| # - Installs Composer dependencies. | ||
| # - Configures caching for PHP static analysis scans. | ||
| # - Make Composer packages available globally. | ||
| # - Runs PHPStan static analysis (with Pull Request annotations). | ||
| # - Saves the PHPStan result cache. | ||
| # - Ensures version-controlled files are not modified or deleted. | ||
| phpstan: | ||
| name: Run PHP static analysis | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: read | ||
| timeout-minutes: 20 | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up PHP | ||
| uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 | ||
| with: | ||
| php-version: ${{ inputs.php-version }} | ||
| coverage: none | ||
| tools: cs2pr | ||
|
|
||
| - name: Log debug information | ||
| run: | | ||
| composer --version | ||
|
|
||
| # This date is used to ensure that the Composer cache is cleared at least once every week. | ||
| # http://man7.org/linux/man-pages/man1/date.1.html | ||
| - name: "Get last Monday's date" | ||
| id: get-date | ||
| run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Since Composer dependencies are installed using `composer update` and no lock file is in version control, | ||
| # passing a custom cache suffix ensures that the cache is flushed at least once per week. | ||
| - name: Install Composer dependencies | ||
| uses: ramsey/composer-install@a2636af0004d1c0499ffca16ac0b4cc94df70565 # v3.1.0 | ||
| with: | ||
| custom-cache-suffix: ${{ steps.get-date.outputs.date }} | ||
|
|
||
| - name: Make Composer packages available globally | ||
| run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH" | ||
|
|
||
| - name: Cache PHP Static Analysis scan cache | ||
| uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | ||
| with: | ||
| path: .cache # This is defined in the base.neon file. | ||
| key: "phpstan-result-cache-${{ github.run_id }}" | ||
| restore-keys: | | ||
| phpstan-result-cache- | ||
|
|
||
| - name: Run PHP static analysis tests | ||
| id: phpstan | ||
| run: phpstan analyse -vvv --error-format=checkstyle | cs2pr | ||
|
|
||
| - name: "Save result cache" | ||
| uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | ||
| if: ${{ !cancelled() }} | ||
| with: | ||
| path: .cache | ||
| key: "phpstan-result-cache-${{ github.run_id }}" | ||
|
|
||
| - name: Ensure version-controlled files are not modified or deleted | ||
| run: git diff --exit-code | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # PHPStan configuration for WordPress Core. | ||
| # | ||
| # To overload this configuration, copy this file to phpstan.neon and adjust as needed. | ||
| # | ||
| # https://phpstan.org/config-reference | ||
|
|
||
| includes: | ||
| # The WordPress Core configuration file includes the base configuration for the WordPress codebase. | ||
| - tests/phpstan/base.neon | ||
| # The baseline file includes preexisting errors in the codebase that should be ignored. | ||
| # https://phpstan.org/user-guide/baseline | ||
|
|
||
| - tests/phpstan/baseline.php # level 0. | ||
| - tests/phpstan/baseline/level-1.php | ||
| - tests/phpstan/baseline/level-2.php | ||
| - tests/phpstan/baseline/level-3.php | ||
| - tests/phpstan/baseline/level-4.php | ||
| - tests/phpstan/baseline/level-5.php | ||
| - tests/phpstan/baseline/level-6.php | ||
|
|
||
| parameters: | ||
| level: 6 | ||
| reportUnmatchedIgnoredErrors: true | ||
|
|
||
| ignoreErrors: | ||
| # Level 0: | ||
| - # Inner functions arent supported by PHPstan. | ||
| message: '#Function wxr_[a-z_]+ not found#' | ||
| path: src/wp-admin/includes/export.php | ||
| - | ||
| identifier: function.inner | ||
| path: src/wp-admin/includes/export.php | ||
| count: 13 | ||
| - | ||
| identifier: function.inner | ||
| path: src/wp-admin/includes/file.php | ||
| count: 1 | ||
| - | ||
| identifier: function.inner | ||
| path: src/wp-includes/canonical.php | ||
| count: 1 | ||
|
|
||
| # Level 1: | ||
| - # These are too noisy at the moment. | ||
| message: '#Variable \$[a-zA-Z0-9_]+ might not be defined\.#' | ||
|
|
||
| # Level 2: | ||
| - # Callable-strings are used as callables in WordPress. | ||
| message: '#Default value of the parameter .* is incompatible with type callable.*#' | ||
|
|
||
| # Level 6: | ||
| - # WPCS syntax for iterable types is not supported. | ||
| identifier: missingType.iterableValue | ||
| - # Too noisy until `void` return types are allowed. | ||
| identifier: missingType.return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The php tests just uses
phpas this variable name while phpcompatability and this new one usephp-version. I think we should make all of these consistent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something to be addressed in this PR, and if so in which direction?
(regular PHPCS also uses
php-versionhttps://github.com/justlevine/wordpress-develop/blob/7391ed6aadf101ca4e6e3c82fe841cbade4358ee/.github/workflows/reusable-coding-standards-php.yml#L9 )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's something that should be addressed before this PR and then this PR may need to be updated. I'll raise a slack discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion for this: https://wordpress.slack.com/archives/C08D0Q6BHNY/p1752520451251869