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

[4.x] Set up PHPStan on GitHub Actions #64

Closed
wants to merge 6 commits into from
Closed

[4.x] Set up PHPStan on GitHub Actions #64

wants to merge 6 commits into from

Conversation

nhedger
Copy link
Contributor

@nhedger nhedger commented Sep 17, 2022

This PR sets up PHPStan to run on GitHub Actions, as discussed in discussions#469.

Overview

  • Sets up PHPStan to run on GitHub Actions on PHP 8.1 only
  • Configures PHPStan to run the analysis on the src and tests folders
  • Generates the baseline so that static analysis passes immediately

Baseline

Because this PR aims to set up PHPStan and not address the errors it reports, I've generated a baseline to make the pipeline succeed. We'll then be able to incrementally fix the problems in future PRs.


Once this has been merged, I'll create PRs for the 3.x and 2.x branches.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
Comment on lines +32 to +35
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP
uses: shivammathur/setup-php@v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove names for consistency with other actions?

Suggested change
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP
uses: shivammathur/setup-php@v2
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I'd rather we add names to the other steps for consistency x)

Comment on lines +40 to +43
- name: Install Composer dependencies
run: composer install
- name: Run static analysis
run: phpstan analyse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove names for consistency with other actions?

Suggested change
- name: Install Composer dependencies
run: composer install
- name: Run static analysis
run: phpstan analyse
- run: composer install
- run: phpstan analyse

Comment on lines +118 to +121
-
message: "#^PHPDoc tag @param for parameter \\$tasks contains generic type React\\\\Promise\\\\PromiseInterface\\<mixed, React\\\\Async\\\\Exception\\> but interface React\\\\Promise\\\\PromiseInterface is not generic\\.$#"
count: 3
path: src/functions.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this was generated as a baseline, but how is this going to affect the build status once Promise actually adds @template definitions via reactphp/promise#227? It's my understanding this would start failing once this error is no longer matched? Does this mean we should fix such errors upstream first?

(Same applies to other occurrences)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit this did not cross my mind. I guess fixing the error upstream would be sensible.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nhedger Thank you for looking into this and filing all PHPStan PRs! 👍 I'll use this PR as a starting point because it only targets a small PHP version range, so I've added a couple of questions (and some minor nits) below, WDYT?

nhedger and others added 3 commits September 19, 2022 20:12
Co-authored-by: Christian Lück <christian@clue.engineering>
Co-authored-by: Christian Lück <christian@clue.engineering>
Co-authored-by: Christian Lück <christian@clue.engineering>
@SimonFrings
Copy link
Member

@nhedger I really like this idea, I'm not sure what's the best way to do this. I see a problem with future contributions to the project. There can (and will be) cases where someone files a PR and something unrelated to their changes shows an error due to a new PHPStan version. We could now tell him to generate a new baseline and that's it, but it feels wrong to see upgrading unrelated parts as the contributors job. It also mixes the actual changes in this persons PR with unrelated changes that needs to be handled in a different pull request. I think it's in everyone's best interest to keep the contribution part as easy as possible, to avoid unnecessary confusion and frustration on the contributors side and keep the review process smaller.

I think the way to avoid this problem is to lock the used PHPStan version as @clue suggested above.

@nhedger
Copy link
Contributor Author

nhedger commented Oct 6, 2022

I've pinned the version of PHPStan to the current latest.

@nhedger nhedger closed this by deleting the head repository Apr 21, 2023
@clue
Copy link
Member

clue commented Apr 24, 2023

@nhedger Was this PR closed intentionally (along with related ones as per https://github.com/orgs/reactphp/discussions/469)? I've also started looking into PHPStan on max level with no baseline a while ago, would you like to keep working on this PR or do you think it makes sense for me to file my PR in comparison? In either case, thank you for your patience and for looking into this!

@nhedger
Copy link
Contributor Author

nhedger commented Apr 24, 2023

Ah sorry, it got closed because I cleaned up my forks. Completely forgot to check for open PRs. Not planning to work on this in the near future, so feel free to file your own PR in the meantime.

@clue
Copy link
Member

clue commented Jun 23, 2023

For the reference: We've recently merged PHPStan on max level into 4.x with #76 and backported to 3.x with #77. Unlike the changes in this PR, we've gone through the project to fix all PHPStan errors encountered so we don't have to rely on a baseline. We'll go ahead with this and apply PHPStan on max level to all our projects in the future.

Thank you very much for your contribution and sparking this discussion! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants