Skip to content

Add static type analysis with PHPStan #227

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

Merged
merged 1 commit into from
May 30, 2021

Conversation

oliverklee
Copy link
Collaborator

@oliverklee oliverklee commented May 27, 2021

Add Composer scripts for checking the code with PHPStan (while using
a baseline) and for updating the baseline.

When we fix PHPStan-reported issues (or update the PHPStan configuration),
we can update the baseline bit by bit until all issues are fixed.

@oliverklee oliverklee force-pushed the feature/phpstan branch 2 times, most recently from 2856cc0 to a58fdcb Compare May 27, 2021 21:20
@oliverklee oliverklee marked this pull request as draft May 27, 2021 21:39
@oliverklee
Copy link
Collaborator Author

Marking as draft again. I think we should start with level 0 first (so that the baseline file is more manageable), and work our way up through the levels.

I'd also like to add this to the CI build.

@sabberworm
Copy link
Collaborator

I'd also like to add this to the CI build.

Feel free to do this. Let the PR CI fail until all code is up to standards.

@oliverklee
Copy link
Collaborator Author

Let the PR CI fail until all code is up to standards.

Even better: With the baseline file, the build will pass with the code as-is, while we still prevent the introduction of new typing issues. Neat, isn't it?

@oliverklee oliverklee force-pushed the feature/phpstan branch 23 times, most recently from c99f706 to e4e3c47 Compare May 28, 2021 11:35
@oliverklee oliverklee marked this pull request as ready for review May 28, 2021 11:37
@oliverklee oliverklee force-pushed the feature/phpstan branch 3 times, most recently from 316a3a2 to 2b35cd4 Compare May 28, 2021 13:10
Comment on lines +1 to +27
parameters:
ignoreErrors:
-
message: "#^Class Sabberworm\\\\CSS\\\\Parsing\\\\ParserState constructor invoked with 1 parameter, 2\\-3 required\\.$#"
count: 1
path: lib/Sabberworm/CSS/CSSList/CSSList.php

-
message: "#^Access to an undefined property Sabberworm\\\\CSS\\\\Parsing\\\\ParserState\\:\\:\\$oParserHelper\\.$#"
count: 1
path: lib/Sabberworm/CSS/Parsing/ParserState.php

-
message: "#^Access to an undefined property Sabberworm\\\\CSS\\\\Property\\\\Charset\\:\\:\\$aComments\\.$#"
count: 5
path: lib/Sabberworm/CSS/Property/Charset.php

-
message: "#^Class PHPUnit\\\\Framework\\\\TestCase referenced with incorrect case\\: PHPunit\\\\Framework\\\\TestCase\\.$#"
count: 1
path: tests/Sabberworm/CSS/OutputFormatTest.php

-
message: "#^Class PHPUnit\\\\Framework\\\\TestCase referenced with incorrect case\\: PHPunit\\\\Framework\\\\TestCase\\.$#"
count: 1
path: tests/Sabberworm/CSS/ParserTest.php

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, I thought there’d be more

Copy link
Collaborator Author

@oliverklee oliverklee May 28, 2021

Choose a reason for hiding this comment

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

That's also because we're starting at level 0. 😄 (The PHPStan levels go up to level 8 …)

phpstan.neon Outdated
@@ -0,0 +1,16 @@
includes:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we name this phpstan.neon.dist as per https://phpstan.org/config-reference#config-file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Changed, rebased and repushed.

@oliverklee oliverklee changed the title Add PHPStan Add static type analysis with PHPStan May 29, 2021
Add Composer scripts for checking the code with PHPStan (while using
a baseline) and for updating the baseline.

When we fix PHPStan-reported issues (or update the PHPStan configuration),
we can update the baseline bit by bit until all issues are fixed.
@oliverklee oliverklee requested a review from sabberworm May 29, 2021 09:14
@sabberworm sabberworm merged commit abf3975 into MyIntervals:master May 30, 2021
@oliverklee oliverklee deleted the feature/phpstan branch May 30, 2021 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants