Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YoastCS rules: verify return type annotations
This sniff: * Disallows plain `array` type annotations. These should always be made specific. * Flags missing type annotations. Optionally the sniff can enforce PHP native type declarations instead of annotations in a docblock. This functionality has been **disabled** for the following reasons: * Adding type declarations without using `strict_types` leads to bugs as the original (scalar) data will be juggled by PHP, even if the original data was never correct to start with. The loss of the type information of the original data passed, means that the function can no longer discern whether the input is invalid/incorrect. Think: a function expecting an integer, but being passed `false`. This will be juggled to `0`, while it should have been flagged as unusable input. * Adding `strict_types` in the context of WP is a no-no to begin with as it can cause fatal errors (= white screen of death) when the exceptions are not caught and they generally are not caught and WP doesn't have a native exception handler in place either. * Adding `strict_types` is useless anyway as it is only enforced for files containing such a declaration, which means that parameters passed to a function call from an external source which doesn't have the `strict_types` declaration (callback called from WP) will still be juggled, which again leads to bugs. * Adding type declarations in functions hooked into WP filters is especially dangerous due to the loss of type info. All in all, with the type system offered by PHP as-is, adding PHP native type declarations is next to useless unless you have full control of all code + the environment the code is being run on, which for the Yoast code is just not the case (with the exception of Platform). Related to 303 Impact on Yoast packages: | Plugin/Tool | Errors/Warnings | |-------------------|-----------------| | PHPUnit Polyfills | 22 | WP Test Utils | 9 | YoastCS | -- | WHIP | 5 | Yoast Test Helper | 21 | Duplicate Post | 44 | Yst ACF | 5 | Yst WooCommerce | 48 | Yst News | 22 | Yst Local | 132 | Yst Video | 237 | Yst Premium | 269 | Yst Free | 1066
- Loading branch information