| Conditions | 6 |
| Paths | 21 |
| Total Lines | 69 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 45 | public function execute(array $values) : array |
||
| 46 | { |
||
| 47 | $editTaskCommand = new EditTaskCommand( |
||
| 48 | $values['id'], |
||
| 49 | $values['title'], |
||
| 50 | $values['description'], |
||
| 51 | $this->currentUser |
||
| 52 | ); |
||
| 53 | $changePriorityCommand = new ChangeTaskPriorityCommand( |
||
| 54 | $values['id'], |
||
| 55 | $values['priority'], |
||
| 56 | $this->currentUser |
||
| 57 | ); |
||
| 58 | $reassignTaskCommand = new ReassignTaskCommand( |
||
| 59 | $values['id'], |
||
| 60 | $values['assigneeId'], |
||
| 61 | $this->currentUser |
||
| 62 | ); |
||
| 63 | $changeParentTaskCommand = new ChangeParentTaskCommand( |
||
| 64 | $values['id'], |
||
| 65 | $this->currentUser, |
||
| 66 | $values['parentId'] ?? null |
||
| 67 | ); |
||
| 68 | |||
| 69 | try { |
||
| 70 | $this->commandBus->handle($editTaskCommand); |
||
| 71 | $this->commandBus->handle($changePriorityCommand); |
||
| 72 | $this->commandBus->handle($reassignTaskCommand); |
||
| 73 | $this->commandBus->handle($changeParentTaskCommand); |
||
| 74 | } catch (TaskDoesNotExistException $exception) { |
||
| 75 | throw new UserError( |
||
| 76 | sprintf( |
||
| 77 | 'The task with "%s" id does not exist', |
||
| 78 | $values['id'] |
||
| 79 | ) |
||
| 80 | ); |
||
| 81 | } catch (UnauthorizedTaskActionException $exception) { |
||
| 82 | throw new UserError( |
||
| 83 | sprintf( |
||
| 84 | 'The "%s" user does not allow to edit the task', |
||
| 85 | $this->currentUser |
||
| 86 | ) |
||
| 87 | ); |
||
| 88 | } catch (TaskAndTaskParentCannotBeTheSameException $exception) { |
||
| 89 | throw new UserError('The task and its parent are the same'); |
||
| 90 | } catch (TaskParentDoesNotExistException $exception) { |
||
| 91 | throw new UserError( |
||
| 92 | sprintf( |
||
| 93 | 'The task parent with "%s" id does not exist', |
||
| 94 | $values['parentId'] |
||
| 95 | ) |
||
| 96 | ); |
||
| 97 | } catch (TaskParentCannotBelongToOtherProjectException $exception) { |
||
| 98 | throw new UserError( |
||
| 99 | sprintf( |
||
| 100 | 'The task parent with "%s" id does not belong to the task\'s project', |
||
| 101 | $values['parentId'] |
||
| 102 | ) |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | $task = $this->taskResolver->resolve([ |
||
| 107 | 'id' => $editTaskCommand->id(), |
||
| 108 | ]); |
||
| 109 | |||
| 110 | return [ |
||
| 111 | 'task' => $task, |
||
| 112 | ]; |
||
| 113 | } |
||
| 114 | } |
||
| 115 |