Conditions | 7 |
Paths | 5 |
Total Lines | 67 |
Code Lines | 47 |
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 |
||
62 | public function __invoke(FilterTasksQuery $query) |
||
63 | { |
||
64 | $userId = UserId::generate($query->userId()); |
||
65 | $projectIds = [ProjectId::generate($query->projectId())]; |
||
66 | $assigneeIds = []; |
||
67 | $reporterIds = []; |
||
68 | |||
69 | $project = $this->projectRepository->projectOfId($projectIds[0]); |
||
70 | if ($project instanceof Project) { |
||
71 | $organization = $this->organizationRepository->organizationOfId( |
||
72 | $project->organizationId() |
||
73 | ); |
||
74 | $assigneeIds = $this->addUserId($assigneeIds, $organization, $query->assigneeId()); |
||
75 | $reporterIds = $this->addUserId($reporterIds, $organization, $query->reporterId()); |
||
76 | |||
77 | if (!$organization->isOrganizationMember($userId)) { |
||
78 | throw new UnauthorizedTaskResourceException(); |
||
79 | } |
||
80 | } else { |
||
81 | $organizations = $this->organizationRepository->query( |
||
82 | $this->organizationSpecificationFactory->buildFilterableSpecification( |
||
83 | null, |
||
84 | $userId |
||
85 | ) |
||
86 | ); |
||
87 | |||
88 | $organizationIds = []; |
||
89 | foreach ($organizations as $organization) { |
||
90 | $assigneeIds = $this->addUserId($assigneeIds, $organization, $query->assigneeId()); |
||
91 | $reporterIds = $this->addUserId($reporterIds, $organization, $query->reporterId()); |
||
92 | |||
93 | $organizationIds[] = $organization->id(); |
||
94 | } |
||
95 | $projects = $this->projectRepository->query( |
||
96 | $this->projectSpecificationFactory->buildFilterableSpecification( |
||
97 | $organizationIds, |
||
98 | null |
||
99 | ) |
||
100 | ); |
||
101 | $projectIds = array_map(function (Project $project) { |
||
102 | return $project->id(); |
||
103 | }, $projects); |
||
104 | } |
||
105 | if (empty($projectIds)) { |
||
106 | return []; |
||
107 | } |
||
108 | |||
109 | $tasks = $this->repository->query( |
||
110 | $this->specificationFactory->buildFilterableSpecification( |
||
111 | $projectIds, |
||
112 | $query->title(), |
||
113 | $this->parentTask($query->parentId(), $userId), |
||
114 | null === $query->priority() ? null : new TaskPriority($query->priority()), |
||
115 | null === $query->progress() ? null : new TaskProgress($query->progress()), |
||
116 | $assigneeIds, |
||
117 | $reporterIds, |
||
118 | $query->offset(), |
||
119 | $query->limit() |
||
120 | ) |
||
121 | ); |
||
122 | |||
123 | return array_map(function (Task $task) { |
||
124 | $this->dataTransformer->write($task); |
||
125 | |||
126 | return $this->dataTransformer->read(); |
||
127 | }, $tasks); |
||
128 | } |
||
129 | |||
165 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.