| Conditions | 9 |
| Paths | 12 |
| Total Lines | 57 |
| Code Lines | 38 |
| 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 |
||
| 50 | public function __invoke(CreateTaskCommand $command) |
||
| 51 | { |
||
| 52 | if (null !== $id = $command->taskId()) { |
||
| 53 | $task = $this->repository->taskOfId( |
||
| 54 | TaskId::generate( |
||
| 55 | $id |
||
| 56 | ) |
||
| 57 | ); |
||
| 58 | if ($command->parentId() === $command->taskId()) { |
||
| 59 | throw new TaskAndTaskParentCannotBeTheSameException(); |
||
| 60 | } |
||
| 61 | if ($task instanceof Task) { |
||
| 62 | throw new TaskAlreadyExistsException(); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | $project = $this->projectRepository->projectOfId( |
||
| 66 | ProjectId::generate( |
||
| 67 | $command->projectId() |
||
| 68 | ) |
||
| 69 | ); |
||
| 70 | if (!$project instanceof Project) { |
||
| 71 | throw new ProjectDoesNotExistException(); |
||
| 72 | } |
||
| 73 | $organization = $this->organizationRepository->organizationOfId( |
||
| 74 | $project->organizationId() |
||
| 75 | ); |
||
| 76 | $creatorId = MemberId::generate(UserId::generate($command->creatorId()), $organization->id()); |
||
| 77 | $assigneeId = MemberId::generate(UserId::generate($command->assigneeId()), $organization->id()); |
||
| 78 | if (!$organization->isMember($creatorId) || !$organization->isMember($assigneeId)) { |
||
| 79 | throw new TaskCreationNotAllowedException(); |
||
| 80 | } |
||
| 81 | if (null !== $parentId = $command->parentId()) { |
||
| 82 | $parent = $this->repository->taskOfId( |
||
| 83 | TaskId::generate( |
||
| 84 | $parentId |
||
| 85 | ) |
||
| 86 | ); |
||
| 87 | if (!$parent instanceof Task) { |
||
| 88 | throw new TaskParentDoesNotExistException(); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | $task = new Task( |
||
| 92 | TaskId::generate($id), |
||
| 93 | new TaskTitle( |
||
| 94 | $command->title() |
||
| 95 | ), |
||
| 96 | $command->description(), |
||
| 97 | $creatorId, |
||
| 98 | $assigneeId, |
||
| 99 | new TaskPriority($command->priority()), |
||
| 100 | $project->id(), |
||
| 101 | TaskId::generate( |
||
| 102 | $parentId |
||
| 103 | ) |
||
| 104 | ); |
||
| 105 | $this->repository->persist($task); |
||
| 106 | } |
||
| 107 | } |
||
| 108 |