PHPStan v1.10.36 releases: PHP Static Analysis Tool
PHPStan – PHP Static Analysis Tool
PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.
What it currently checks for?
- Existence of classes used in instanceof, catch, typehints and other language constructs. PHP does not check this and just stays instead, rendering the surrounded code unused.
- Existence and accessibility of called methods and functions. It also checks the number of passed arguments.
- Whether a method returns the same type it declares to return.
- Existence and visibility of accessed properties. It will also point out if a different type from the declared one is assigned to the property.
- The correct number of parameters passed to sprintf/printf calls based on format strings.
- Existence of variables while respecting scopes of branches and loops.
- Useless casting like (string) ‘foo’ and strict comparisons (=== and !==) with different types as operands which always result in false.
PHPStan is fast…
It manages to check the whole codebase in a single pass. It doesn’t need to go through the code multiple times. And it only needs to go through the code you wish to analyze, e.g. the code you have written. It doesn’t need to parse and analyze 3rd party dependencies. Instead, it uses reflection to find out useful information about somebody else’s code your codebase uses.
PHPStan is able to check our codebase (6000 files, 600k LOCs) in around a minute. And it checks itself under a second.
reportUncheckedExceptionDeadCatchoption (defaults to
true) (#2648), #9921, thanks @VincentLanglet!
- Support union types in
array_chunk()(#2635), thanks @staabm!
- Result cache: Indicate key differences in cache metadata (#2630), thanks @staabm!
- Get rid of annoying “on an unknown class ReflectionEnum” error on PHP < 8.0 (phpstan/phpstan-src@2b9af36)
- Fix resolving nested conditional types with union subjects (#2641), #9860, thanks @rvanvelzen!
- Detect array_rand second parameter (#2633), #9803, thanks @staabm!
- Fix subtracting types from union template types (#2652), #9939, thanks @rvanvelzen!
- fix infinite cycle due to incorrect implements/extends (#2483), thanks @schlndh!
- Fix ConstantFloatType value dump precision (#2358), thanks @mvorisek!
- Do not trigger PhpDocInheritanceResolver if we do not need the PHPDoc type when resolving the type of ClassConstFetch (#2414), #9039, thanks @VincentLanglet!
Function signature fixes 🤖
connection_*functions are impure (#2555), thanks @staabm!
- Add stubs for
mysqli_resultclasses (#2295), thanks @phansys!
- E2E test about env variables in config parameters (phpstan/phpstan-src@980ab5b)
- Prevent unnecessary calls to
getFiniteTypes()(#2636), thanks @staabm!
- Remove unnecessary IO (#2613), thanks @staabm!
- Restrict “Merge maintained branch” workflow to the main repository (#2654), thanks @thg2k!
Copyright (c) 2016 Ondřej Mirtes