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 |
||
13 | class DispatchConditionMetadata |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | const CONDITION_RUN_TYPE_SERVICE = 'service'; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | const CONDITION_RUN_TYPE_METHOD = 'method'; |
||
24 | |||
25 | /** |
||
26 | * Разрешенные типы запуска workflow |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $allowConditionRunType = [ |
||
31 | self::CONDITION_RUN_TYPE_SERVICE => self::CONDITION_RUN_TYPE_SERVICE, |
||
32 | self::CONDITION_RUN_TYPE_METHOD => self::CONDITION_RUN_TYPE_METHOD |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Тип запуска обработчика проверки условий |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $type; |
||
41 | |||
42 | /** |
||
43 | * Определяет обработчик для провекри условий |
||
44 | * |
||
45 | * @var string |
||
46 | * |
||
47 | */ |
||
48 | protected $handler; |
||
49 | |||
50 | /** |
||
51 | * Параметры обработчика |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $params = []; |
||
56 | |||
57 | /** |
||
58 | * @param $type |
||
59 | * @param $handler |
||
60 | * @param array $params |
||
61 | * |
||
62 | * @throws Exception\InvalidMetadataException |
||
63 | */ |
||
64 | public function __construct($type, $handler, array $params = []) |
||
70 | |||
71 | /** |
||
72 | * Тип запуска обработчика проверки условий |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getType() |
||
80 | |||
81 | /** |
||
82 | * Устанавливает тип запуска обработчика проверки условий |
||
83 | * |
||
84 | * @param string $type |
||
85 | * |
||
86 | * @return $this |
||
87 | * |
||
88 | * @throws Exception\InvalidMetadataException |
||
89 | */ |
||
90 | View Code Duplication | public function setType($type) |
|
100 | |||
101 | /** |
||
102 | * Определяет обработчик для провекри условий |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getHandler() |
||
110 | |||
111 | /** |
||
112 | * Устанавливает обработчик для провекри условий |
||
113 | * |
||
114 | * @param string $handler |
||
115 | * |
||
116 | * @return $this |
||
117 | */ |
||
118 | public function setHandler($handler = null) |
||
124 | |||
125 | /** |
||
126 | * @return array |
||
127 | */ |
||
128 | public function getParams() |
||
132 | |||
133 | /** |
||
134 | * @param array $params |
||
135 | * |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function setParams(array $params = []) |
||
144 | |||
145 | /** |
||
146 | * |
||
147 | * @throws Exception\InvalidMetadataException |
||
148 | */ |
||
149 | public function validate() |
||
164 | } |
||
165 |
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.