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 |
||
9 | class ObjectView implements ViewInterface, \ArrayAccess, \Iterator |
||
10 | { |
||
11 | private $template; |
||
12 | private $viewClosures; |
||
13 | |||
14 | public function __construct(string $template, array $viewClosures) |
||
19 | |||
20 | View Code Duplication | public function offsetGet($name) |
|
31 | |||
32 | public function offsetExists($name) |
||
36 | |||
37 | public function offsetSet($name, $value) |
||
43 | |||
44 | public function offsetUnset($name) |
||
50 | |||
51 | public function current() |
||
55 | |||
56 | public function key() |
||
60 | |||
61 | public function next() |
||
65 | |||
66 | public function rewind() |
||
70 | |||
71 | public function valid() |
||
75 | |||
76 | public function getTemplate(): string |
||
80 | } |
||
81 |
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.