Conditions | 7 |
Paths | 5 |
Total Lines | 58 |
Code Lines | 41 |
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(CountTasksQuery $query) : int |
||
58 | { |
||
59 | $userId = UserId::generate($query->userId()); |
||
60 | $projectIds = [ProjectId::generate($query->projectId())]; |
||
61 | $assigneeIds = []; |
||
62 | $reporterIds = []; |
||
63 | |||
64 | $project = $this->projectRepository->projectOfId($projectIds[0]); |
||
65 | if ($project instanceof Project) { |
||
66 | $organization = $this->organizationRepository->organizationOfId( |
||
67 | $project->organizationId() |
||
68 | ); |
||
69 | $assigneeIds = $this->addUserId($assigneeIds, $organization, $query->assigneeId()); |
||
70 | $reporterIds = $this->addUserId($reporterIds, $organization, $query->reporterId()); |
||
71 | |||
72 | if (!$organization->isOrganizationMember($userId)) { |
||
73 | throw new UnauthorizedTaskResourceException(); |
||
74 | } |
||
75 | } else { |
||
76 | $organizations = $this->organizationRepository->query( |
||
77 | $this->organizationSpecificationFactory->buildFilterableSpecification( |
||
78 | null, |
||
79 | $userId |
||
80 | ) |
||
81 | ); |
||
82 | $organizationIds = []; |
||
83 | foreach ($organizations as $organization) { |
||
84 | $assigneeIds = $this->addUserId($assigneeIds, $organization, $query->assigneeId()); |
||
85 | $reporterIds = $this->addUserId($reporterIds, $organization, $query->reporterId()); |
||
86 | |||
87 | $organizationIds[] = $organization->id(); |
||
88 | } |
||
89 | $projects = $this->projectRepository->query( |
||
90 | $this->projectSpecificationFactory->buildFilterableSpecification( |
||
91 | $organizationIds, |
||
92 | null |
||
93 | ) |
||
94 | ); |
||
95 | $projectIds = array_map(function (Project $project) { |
||
96 | return $project->id(); |
||
97 | }, $projects); |
||
98 | } |
||
99 | if (empty($projectIds)) { |
||
100 | return 0; |
||
101 | } |
||
102 | |||
103 | return $this->repository->count( |
||
104 | $this->specificationFactory->buildFilterableSpecification( |
||
105 | $projectIds, |
||
106 | $query->title(), |
||
107 | $this->parentTask($query->parentId(), $userId), |
||
108 | null === $query->priority() ? null : new TaskPriority($query->priority()), |
||
109 | null === $query->progress() ? null : new TaskProgress($query->progress()), |
||
110 | $assigneeIds, |
||
111 | $reporterIds |
||
112 | ) |
||
113 | ); |
||
114 | } |
||
115 | |||
151 |
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.