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 | View Code Duplication | class SerializerPluginOptions extends AbstractOptions |
|
|
|||
16 | { |
||
17 | /** |
||
18 | * Имя плагина |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $name; |
||
23 | |||
24 | /** |
||
25 | * Настройки плагина |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $options = []; |
||
30 | |||
31 | /** |
||
32 | * Настройки для сериалайзера |
||
33 | * |
||
34 | * @var SerializerOptions |
||
35 | */ |
||
36 | protected $serializerOptions; |
||
37 | |||
38 | /** |
||
39 | * Возвращает имя плагина |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | public function getName() |
||
47 | |||
48 | /** |
||
49 | * Устанавливает имя плагина |
||
50 | * |
||
51 | * @param string $name |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | public function setName($name) |
||
61 | |||
62 | /** |
||
63 | * Возвращает настройки плагина |
||
64 | * |
||
65 | * @return SerializerOptions |
||
66 | */ |
||
67 | public function getOptions() |
||
75 | |||
76 | /** |
||
77 | * Устанавливает настройки плагина |
||
78 | * |
||
79 | * @param array $options |
||
80 | * |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function setOptions(array $options) |
||
89 | } |
||
90 |
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.