Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 15 | final class MethodDocBlock |
||
| 16 | { |
||
| 17 | |||
| 18 | 1 | View Code Duplication | public static function hasMethodDocBlock(PHP_CodeSniffer_File $file, int $position) : bool |
| 35 | |||
| 36 | |||
| 37 | 1 | public static function getMethodDocBlock(PHP_CodeSniffer_File $file, int $position) : string |
|
| 47 | |||
| 48 | } |
||
| 49 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.