You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[PHPStan](https://github.com/phpstan/phpstan) focuses on finding bugs in your code. But in PHP there's a lot of leeway in how stuff can be written. This repository contains additional rules that revolve around strictly and strongly typed code with no loose casting for those who want additional safety in extremely defensive programming:
7
+
[PHPStan](https://phpstan.org/) focuses on finding bugs in your code. But in PHP there's a lot of leeway in how stuff can be written. This repository contains additional rules that revolve around strictly and strongly typed code with no loose casting for those who want additional safety in extremely defensive programming:
8
8
9
9
* Require booleans in `if`, `elseif`, ternary operator, after `!`, and on both sides of `&&` and `||`.
10
10
* Require numeric operands or arrays in `+` and numeric operands in `-`/`*`/`/`/`**`/`%`.
@@ -15,30 +15,46 @@
15
15
*`array_keys` (3rd parameter; only if the 2nd parameter `$search_value` is provided)
16
16
*`base64_decode` (2nd parameter)
17
17
* Variables assigned in `while` loop condition and `for` loop initial assignment cannot be used after the loop.
18
+
* Variables set in foreach that's always looped thanks to non-empty arrays cannot be used after the loop.
18
19
* Types in `switch` condition and `case` value must match. PHP compares them loosely by default and that can lead to unexpected results.
19
-
*Statically declared methods are called statically.
20
+
*Check that statically declared methods are called statically.
20
21
* Disallow `empty()` - it's a very loose comparison (see [manual](https://php.net/empty)), it's recommended to use more strict one.
22
+
* Disallow short ternary operator (`?:`) - implies weak comparison, it's recommended to use null coalesce operator (`??`) or ternary operator with strict condition.
* Disallow overwriting variables with foreach key and value variables
21
25
* Always true `instanceof`, type-checking `is_*` functions and strict comparisons `===`/`!==`. These checks can be turned off by setting `checkAlwaysTrueInstanceof`/`checkAlwaysTrueCheckTypeFunctionCall`/`checkAlwaysTrueStrictComparison` to false.
22
-
* Require parameter and return typehints for functions and methods (either native or phpDocs)
23
26
* Correct case for referenced and called function names.
24
27
* Correct case for inherited and implemented method names.
28
+
* Contravariance for parameter types and covariance for return types in inherited methods (also known as Liskov substitution principle - LSP)
29
+
* Check LSP even for static methods
30
+
* Check missing typehint in anonymous function when a native one could be added
0 commit comments