| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @link https://github.com/old-town/old-town-workflow | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @author  Malofeykin Andrey  <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | namespace OldTown\Workflow\Engine; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use OldTown\Workflow\Exception\InternalWorkflowException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use OldTown\Workflow\Exception\InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use OldTown\Workflow\Loader\ActionDescriptor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Traversable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use DateTime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Class Entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @package OldTown\Workflow\Engine | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class Entry extends AbstractEngine implements EntryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @param ActionDescriptor $action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param                  $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @param array|Traversable $currentSteps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @param                  $state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @throws InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @throws InternalWorkflowException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |     public function completeEntry(ActionDescriptor $action = null, $id, $currentSteps, $state) | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 34 |  | View Code Duplication |         if (!is_array($currentSteps) && !$currentSteps  instanceof Traversable) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |             $errMsg = 'Invalid currentSteps'; | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |             throw new InvalidArgumentException($errMsg); | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |         $workflowManager = $this->getWorkflowManager(); | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |         $context = $workflowManager->getContext(); | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |         $store = $workflowManager->getConfiguration()->getWorkflowStore(); | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |         $store->setEntryState($id, $state); | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |         $oldStatus = null !== $action ? $action->getUnconditionalResult()->getOldStatus() : 'Finished'; | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         $actionIdValue = null !== $action ? $action->getId() : -1; | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         foreach ($currentSteps as $step) { | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             $store->markFinished($step, $actionIdValue, new DateTime(), $oldStatus, $context->getCaller()); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |             $store->moveToHistory($step); | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 52 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                        
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.