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