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 |
||
8 | class Expressions |
||
9 | { |
||
10 | View Code Duplication | public static function unsetFunc(string $object, string $property): Node\Stmt\Expression |
|
19 | |||
20 | View Code Duplication | public static function issetFunc(string $object, string $property): Node\Expr\FuncCall |
|
29 | |||
30 | public static function inConstArrayFunc(string $name, string $object, string $haystackConst): Node\Expr\FuncCall |
||
39 | |||
40 | public static function resolveIntoVar(string $var, string $object, string $property, string $method): Node\Stmt\Expression |
||
49 | |||
50 | public static function resolveMethodCall(string $object, string $property, string $method): Node\Expr\MethodCall |
||
54 | |||
55 | public static function resolvePropertyFetch(string $object, string $property): Node\Expr\PropertyFetch |
||
59 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.