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 RunWorkflowParam implements RunWorkflowParamInterface |
||
14 | { |
||
15 | /** |
||
16 | * Тип запуска workflow (doAction или initialize) |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $runType; |
||
21 | |||
22 | /** |
||
23 | * Имя менеджера workflow |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $managerName; |
||
28 | |||
29 | /** |
||
30 | * Имя запускаемого действия |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $actionName; |
||
35 | |||
36 | /** |
||
37 | * Имя workflow |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $workflowName; |
||
42 | |||
43 | /** |
||
44 | * id запускаемого процесса |
||
45 | * |
||
46 | * @var integer |
||
47 | */ |
||
48 | protected $entryId; |
||
49 | |||
50 | /** |
||
51 | * Разрешенные типы запуска workflow |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $allowWorkflowRunType = [ |
||
56 | self::WORKFLOW_RUN_TYPE_DO_ACTION => self::WORKFLOW_RUN_TYPE_DO_ACTION, |
||
57 | self::WORKFLOW_RUN_INITIALIZE => self::WORKFLOW_RUN_INITIALIZE, |
||
58 | ]; |
||
59 | |||
60 | /** |
||
61 | * Возвращает тип запуска workflow (doAction или initialize) |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getRunType() |
||
69 | |||
70 | /** |
||
71 | * Устанавливает тип запуска workflow (doAction или initialize) |
||
72 | * |
||
73 | * @param string $runType |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function setRunType($runType) |
||
83 | |||
84 | /** |
||
85 | * Имя запускаемого действия |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getActionName() |
||
93 | |||
94 | /** |
||
95 | * Устанавливает имя запускаемого действия |
||
96 | * |
||
97 | * @param string $actionName |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function setActionName($actionName) |
||
107 | |||
108 | /** |
||
109 | * Имя workflow |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getWorkflowName() |
||
117 | |||
118 | /** |
||
119 | * Устанавливает имя workflow |
||
120 | * |
||
121 | * @param string $workflowName |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | public function setWorkflowName($workflowName) |
||
131 | |||
132 | /** |
||
133 | * id запускаемого процесса |
||
134 | * |
||
135 | * @return int |
||
136 | */ |
||
137 | public function getEntryId() |
||
141 | |||
142 | /** |
||
143 | * Устанавливает id запускаемого процесса |
||
144 | * |
||
145 | * @param int $entryId |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | public function setEntryId($entryId) |
||
155 | |||
156 | /** |
||
157 | * Возвращает имя менеджера workflow |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getManagerName() |
||
165 | |||
166 | /** |
||
167 | * Устанавливает имя менеджера workflow |
||
168 | * |
||
169 | * @param string $managerName |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setManagerName($managerName) |
||
179 | |||
180 | /** |
||
181 | * Проверка валидности параметров |
||
182 | * |
||
183 | * @throws Exception\InvalidArgumentException |
||
184 | */ |
||
185 | public function valid() |
||
213 | } |
||
214 |
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.