PHPStan v0.12.34 releases: 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.
@mixinabove classes with
__callStatic()creates static methods (phpstan/phpstan-src@aa38695), #3641
- Detect cache saving error (phpstan/phpstan-src@542238a), #3638
- Updated nikic/php-parser to 4.7.0 (phpstan/phpstan-src@5a3deae)
- Improved PHP 8 compatibility after Treat namespaced names as single token RFC got merged into php-src
yieldin for loop, foreach loop, while loop, do-while loop, if condition, switch statement (#286), thanks @dantleech!
- Fix missing method
Generator::throw()(phpstan/phpstan-src@153c874), #3683, #3418
- Fix anonymous class with PHPDoc (#283), #3661, thanks @dbrekelmans!
Function signature fixes 🤖
- PDO::exec could also return false (#281), thanks @Slamdunk!
- Allowing null as limit for mb_strcut (#284), thanks @balazscsaba2006!
- proc_get_status return type: use array shape according to doc; can also return false (#288), thanks @Slamdunk!
Copyright (c) 2016 Ondřej Mirtes