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 |
||
10 | class SettingsStorage extends Component implements SettingsStorageInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var Application |
||
14 | */ |
||
15 | private $app; |
||
16 | |||
17 | public function __construct(Application $app) |
||
18 | { |
||
19 | $this->app = $app; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @inheritdoc |
||
24 | */ |
||
25 | View Code Duplication | public function setGlobal($key, $value) |
|
33 | |||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | View Code Duplication | public function setBounded($key, $value) |
|
45 | |||
46 | /** |
||
47 | * @inheritdoc |
||
48 | */ |
||
49 | View Code Duplication | public function getGlobal($key) |
|
58 | |||
59 | /** |
||
60 | * @inheritdoc |
||
61 | */ |
||
62 | View Code Duplication | public function getBounded($key) |
|
71 | |||
72 | /** |
||
73 | * Performs request to the API |
||
74 | * @param string $key |
||
75 | * @param array $value |
||
76 | * @return array |
||
77 | */ |
||
78 | private function perform($action, $data) |
||
86 | |||
87 | private function decodeResponse($response) |
||
93 | } |
||
94 |
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.