Conditions | 2 |
Paths | 2 |
Total Lines | 15 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | #!/usr/bin/env php |
||
11 | function checkPhpDocTypes(): void |
||
12 | { |
||
13 | $content = shell_exec('git diff --cached') ?? shell_exec('git diff') ?? shell_exec('git show HEAD'); |
||
14 | preg_match_all('~^\+ +\* @(param|var) (mixed|string|int|float|bool|null|array|\?|\|)+( \$\w+)?$~m', "$content", $parameters); |
||
15 | preg_match_all('~^\+ +\* @return (mixed|string|int|float|bool|null|array|void|\?|\|)+$~m', "$content", $returns); |
||
16 | |||
17 | $errors = [ |
||
18 | ...$parameters[0], |
||
19 | ...$returns[0], |
||
20 | ]; |
||
21 | |||
22 | if ($errors) { |
||
23 | echo 'PHP native types must be used instead of PHPDoc types (without comments), for the following lines:' . PHP_EOL . PHP_EOL; |
||
24 | echo implode(PHP_EOL, $errors) . PHP_EOL; |
||
25 | exit(1); |
||
26 | } |
||
30 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.