| Conditions | 5 |
| Paths | 5 |
| Total Lines | 60 |
| Code Lines | 42 |
| 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 |
||
| 57 | public function __invoke(CreateTaskCommand $command) |
||
| 58 | { |
||
| 59 | $taskId = $command->taskId(); |
||
| 60 | $parentTaskId = $command->parentId(); |
||
| 61 | |||
| 62 | if (!$this->areTaskAndParentIdsDifferent($taskId, $parentTaskId)) { |
||
| 63 | throw new TaskAndTaskParentCannotBeTheSameException(); |
||
| 64 | } |
||
| 65 | |||
| 66 | $task = $this->repository->taskOfId(TaskId::generate($taskId)); |
||
| 67 | if ($this->doesTaskExist($task)) { |
||
| 68 | throw new TaskAlreadyExistsException(); |
||
| 69 | } |
||
| 70 | |||
| 71 | $parentTask = $this->repository->taskOfId(TaskId::generate($parentTaskId)); |
||
| 72 | if (!$this->doesParentTaskExist($parentTaskId, $parentTask)) { |
||
| 73 | throw new TaskParentDoesNotExistException(); |
||
| 74 | } |
||
| 75 | |||
| 76 | $projectId = $command->projectId(); |
||
| 77 | $project = $this->projectRepository->projectOfId(ProjectId::generate($projectId)); |
||
| 78 | if (!$this->doesProjectExist($project)) { |
||
| 79 | throw new ProjectDoesNotExistException(); |
||
| 80 | } |
||
| 81 | |||
| 82 | $organizationId = $project->organizationId(); |
||
| 83 | $reporterId = UserId::generate($command->reporterId()); |
||
| 84 | $assigneeId = UserId::generate($command->assigneeId()); |
||
| 85 | |||
| 86 | $organization = $this->organizationRepository->organizationOfId($organizationId); |
||
| 87 | |||
| 88 | $this->checkUsersAreOrganizationMembers($organization, $reporterId, $assigneeId); |
||
| 89 | |||
| 90 | $taskId = TaskId::generate($taskId); |
||
| 91 | $title = new TaskTitle($command->title()); |
||
| 92 | $description = $command->description(); |
||
| 93 | $reporter = $this->becomeUserIdToDomainMemberId($organization, $reporterId); |
||
| 94 | $assignee = $this->becomeUserIdToDomainMemberId($organization, $assigneeId); |
||
| 95 | $priority = new TaskPriority($command->priority()); |
||
| 96 | $projectId = ProjectId::generate($projectId); |
||
| 97 | $parentTaskId = $this->parentTaskId($parentTaskId); |
||
| 98 | |||
| 99 | $tasksNumber = $this->repository->count( |
||
| 100 | $this->specificationFactory->buildByProjectSpecification($projectId) |
||
| 101 | ); |
||
| 102 | $numericId = NumericId::fromPrevious($tasksNumber); |
||
| 103 | |||
| 104 | $task = new Task( |
||
| 105 | $taskId, |
||
| 106 | $numericId, |
||
| 107 | $title, |
||
| 108 | $description, |
||
| 109 | $reporter, |
||
| 110 | $assignee, |
||
| 111 | $priority, |
||
| 112 | $projectId, |
||
| 113 | $parentTaskId |
||
| 114 | ); |
||
| 115 | $this->repository->persist($task); |
||
| 116 | } |
||
| 117 | |||
| 171 |