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 |
||
23 | class SimpleDirective extends Directive implements DirectiveInterface |
||
24 | { |
||
25 | /** |
||
26 | * Confirms if the directive contains a specified directive. |
||
27 | * |
||
28 | * @param string $name the directive for which to check existence |
||
29 | * |
||
30 | * @return bool true if the sub-directive exists, false otherwise |
||
31 | */ |
||
32 | 1 | public function hasDirective($name) |
|
36 | |||
37 | /** |
||
38 | * Confirms if the directive is simple. |
||
39 | * |
||
40 | * Simple directive cannot have sub directive |
||
41 | * |
||
42 | * @return bool true if the directive is simple, false otherwise |
||
43 | */ |
||
44 | 1 | public function isSimple() |
|
48 | |||
49 | /** |
||
50 | * Dumps the directive respecting a server syntax. |
||
51 | * |
||
52 | * @param ServerInterface $server a server instance |
||
53 | * @param int $spaces the indentation spaces |
||
54 | * |
||
55 | * @return string the dumped directive |
||
56 | */ |
||
57 | 1 | View Code Duplication | public function dump(ServerInterface $server, $spaces = 0) |
67 | } |
||
68 |
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.