For the most part this is only changes to comments, but there are a couple of code changes too:
methods that can return null need an explicit return null statement — a bare return or no return at all are both errors
passing an int to ini_set and passing null to preg_match are flagged as errors, so these have been fixed
Additionally, some errors have been ignored:
some of our Guzzle compatibility code errors because we check for methods that don't exist on new versions. We'll need to run PHPStan against multiple versions of Guzzle to fully check these (this will be done in a future PR)
some code exists for PHP 5 compatibility, but PHPStan doesn't run on PHP <7.1 so this errors as well. When we drop PHP 5 support we can also remove this compatibility code, which will solve these errors
we use new static(...) in a few places, which is unsafe as there's guarantee that child classes will share the same constructor signature (see this article). We can't fix this without a potential BC break, so have to ignore this for now
Design
This PR stops at level 6 because this is where the levels become tricky to update to. Level 6 specifically adds checking for iterable types, e.g. a bare array should really be array<KeyType, ValueType>. I've turned this option off for now as we get around 100 errors from it, but this will be turned on in a future PR. Until then, I've not advanced any further as additional errors can appear as a consequence of adding stricter iterable types
Goal
PHPStan is a static analyser for PHP that can catch a bunch of potential bugs in code
This PR is based on https://github.com/bugsnag/bugsnag-php/pull/633, but runs at level 6 instead of max — PHPStan has 9 error levels (currently) that go from loosest (1) - strictest (9)
For the most part this is only changes to comments, but there are a couple of code changes too:
null
need an explicitreturn null
statement — a barereturn
or noreturn
at all are both errorsint
toini_set
and passingnull
topreg_match
are flagged as errors, so these have been fixedAdditionally, some errors have been ignored:
new static(...)
in a few places, which is unsafe as there's guarantee that child classes will share the same constructor signature (see this article). We can't fix this without a potential BC break, so have to ignore this for nowDesign
This PR stops at level 6 because this is where the levels become tricky to update to. Level 6 specifically adds checking for iterable types, e.g. a bare
array
should really bearray<KeyType, ValueType>
. I've turned this option off for now as we get around 100 errors from it, but this will be turned on in a future PR. Until then, I've not advanced any further as additional errors can appear as a consequence of adding stricter iterable typesTesting
PHPStan now runs on CI on both PHP 7.1 & 8.1