Skip to content

Commit 7df86c9

Browse files
README.md: Add a section on PHPStan use
1 parent 9785259 commit 7df86c9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,45 @@ Read more about available features on the [Clockwork website](https://undergroun
142142
<img width="150px" src="https://github.com/itsgoingd/clockwork/raw/master/.github/assets/footer.png">
143143
</a>
144144
</p>
145+
146+
## Hacking
147+
148+
### PHPStan Static Analyzer Integration
149+
150+
All code is checked for common flaws using [PHPStan](https://phpstan.org), a
151+
static code analyzer.
152+
This is executed in a Github action defined in .github/workflows/phpstan.yaml.
153+
154+
#### Running PHPStan Locally
155+
156+
You can execute it using `vendor/bin/phpstan analyze`.
157+
If you fix any of the existing flaws, you have to remove them from the
158+
baseline (phpstan-baseline.neon), either manually or by regenerating
159+
the baseline.
160+
If you add any flaw, first choice is of course to improve the code, but
161+
if the code is sound and PHPStan reports a false positive, you can also
162+
regenerate the baseline.
163+
In order to regenerate the baseline, run `vendor/bin/phpstan analyze
164+
--generate-baseline`.
165+
166+
#### Troubleshooting
167+
168+
- I get different flaws locally than those reported by the Github action:
169+
This can easily happen when your local environment does not match the one
170+
on Github. In particular, the PHP version, the installed extensions but
171+
also packages that you have installed locally. In that case, you can't
172+
easily use the local results. Perhaps the easiest way would be to use a
173+
Docker container that is set up to resemble the Github environment.
174+
- PHPStan complains about a flaw, but I already fixed it:
175+
Check the error message carefully, PHPStan will tell you if you fix a flaw,
176+
but leave an exception in the baseline. In that case, remove the flaw from
177+
the baseline.
178+
- I get complaints about some code that is totally valid:
179+
Sometimes, PHPStan reports false positives, too. In that case, consider
180+
filing a bug ticket (maybe it already exists even?), and add the flaw to
181+
the baseline.
182+
- I don't have any changes at all, but still get complaints:
183+
This can happen if e.g. PHPStan itself is not the same version as the one
184+
executed by the Github action. Newer versions may find additional flaws
185+
or maybe not flag some valid code as false positive. Since we don't lock
186+
the installed version (using composer.lock), this can happen.

0 commit comments

Comments
 (0)