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 |
||
27 | class WorkflowEngineContext implements Context, SnippetAcceptingContext |
||
28 | { |
||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $workflows = []; |
||
33 | |||
34 | /** |
||
35 | * @var null|callable |
||
36 | */ |
||
37 | protected $callbackFactory; |
||
38 | |||
39 | /** |
||
40 | * @var BasicWorkflow |
||
41 | */ |
||
42 | protected $workflowManager; |
||
43 | |||
44 | /** |
||
45 | * @var bool |
||
46 | */ |
||
47 | protected $flagInitWorkflowManager = false; |
||
48 | |||
49 | /** |
||
50 | * Ключем является alias для идендфикатора запущенного процесса workflow. А значением id этого процесса |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $entryAliasToEntryId = []; |
||
55 | |||
56 | /** |
||
57 | * @var Exception|null |
||
58 | */ |
||
59 | protected $lastException; |
||
60 | |||
61 | /** |
||
62 | * @var TransientVarsInterface |
||
63 | */ |
||
64 | protected $transientVars; |
||
65 | |||
66 | /** |
||
67 | * |
||
68 | */ |
||
69 | public function __construct() |
||
73 | |||
74 | /** |
||
75 | * @return void |
||
76 | */ |
||
77 | protected function init() |
||
86 | |||
87 | /** |
||
88 | * @BeforeScenario |
||
89 | */ |
||
90 | public function beforeScenarioHandler() |
||
99 | |||
100 | /** |
||
101 | * @Given : Registrate the workflow with the name :workflowName. With xml: |
||
102 | * |
||
103 | * @param string $workflowName |
||
104 | * @param PyStringNode $xml |
||
105 | * |
||
106 | * @throws RuntimeException |
||
107 | */ |
||
108 | public function registerAWorkflowWithTheNameWithXml($workflowName, PyStringNode $xml) |
||
125 | |||
126 | /** |
||
127 | * @param PyStringNode $xml |
||
128 | * |
||
129 | * @return WorkflowDescriptor |
||
130 | * |
||
131 | * @throws RuntimeException |
||
132 | */ |
||
133 | public function createWorkflowDescriptor(PyStringNode $xml) |
||
170 | |||
171 | /** |
||
172 | * @Given Create workflow manager |
||
173 | * |
||
174 | * @throws RuntimeException |
||
175 | */ |
||
176 | public function createWorkflowManager() |
||
199 | |||
200 | /** |
||
201 | * @When Progress workflow with alias :entryAlias. Workflow name: :workflowName. Initial action id: :initialAction |
||
202 | * |
||
203 | * @param string $entryAlias |
||
204 | * @param string $workflowName |
||
205 | * @param integer $initialAction |
||
206 | * |
||
207 | * @throws \RuntimeException |
||
208 | */ |
||
209 | View Code Duplication | public function initializeWorkflowEntry($entryAlias, $workflowName, $initialAction) |
|
227 | |||
228 | /** |
||
229 | * @When Call action with id=:actionId for workflow process with alias :entryAlias |
||
230 | * |
||
231 | * @param $entryAlias |
||
232 | * @param $actionId |
||
233 | * |
||
234 | * @throws \RuntimeException |
||
235 | */ |
||
236 | View Code Duplication | public function callActionWithIdForWorkflowProcessWithAlias($entryAlias, $actionId) |
|
254 | |||
255 | /** |
||
256 | * @Then Last action was the result of class exception :exceptionClassName. The massage of exception: :exceptionText |
||
257 | * |
||
258 | * @param $exceptionClassName |
||
259 | * @param $exceptionText |
||
260 | * |
||
261 | * @throws \RuntimeException |
||
262 | */ |
||
263 | public function lastActionWasTheResultOfClassExceptionTheMassageOfException($exceptionClassName, $exceptionText) |
||
275 | |||
276 | /** |
||
277 | * @return BasicWorkflow |
||
278 | * |
||
279 | * @throws \RuntimeException |
||
280 | */ |
||
281 | protected function getWorkflowManager() |
||
290 | |||
291 | /** |
||
292 | * @param string $entryAlias |
||
293 | * @return integer |
||
294 | * |
||
295 | * @throws \RuntimeException |
||
296 | */ |
||
297 | protected function getEntryIdByAlias($entryAlias) |
||
306 | |||
307 | /** |
||
308 | * @Then Process of workflow with the alias :entryAlias has the below steps: |
||
309 | * |
||
310 | * @param string $entryAlias |
||
311 | * @param TableNode $steps |
||
312 | * |
||
313 | * @throws \RuntimeException |
||
314 | */ |
||
315 | public function validateCurrentSteps($entryAlias, TableNode $steps) |
||
343 | |||
344 | /** |
||
345 | * @Then Exceptions are missing |
||
346 | * |
||
347 | * @throws RuntimeException |
||
348 | */ |
||
349 | public function exceptionsAreMissing() |
||
355 | |||
356 | /** |
||
357 | * @Then There is the valuable :name with value :value in Transient Vars |
||
358 | * |
||
359 | * @param string $name |
||
360 | * @param string $value |
||
361 | * |
||
362 | * @throws \RuntimeException |
||
363 | */ |
||
364 | public function thereIsTheValuableWithValueInTransientVars($name, $value) |
||
377 | } |
||
378 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: