| Conditions | 13 |
| Paths | 160 |
| Total Lines | 45 |
| Code Lines | 29 |
| 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 |
||
| 64 | public function get(Params $params, $allowDraft = false) |
||
| 65 | { |
||
| 66 | /* @var \Jobs\Repository\Job $jobRepository */ |
||
| 67 | $jobRepository = $this->repositoryService->get('Jobs/Job'); |
||
| 68 | $idFromRoute = $params('id', 0); |
||
| 69 | $idFromQuery = $params->fromQuery('id', 0); |
||
| 70 | $idFromSubForm = $params->fromPost('job', 0); |
||
| 71 | |||
| 72 | $id = empty($idFromRoute)? (empty($idFromQuery)?$idFromSubForm:$idFromQuery) : $idFromRoute; |
||
| 73 | $snapshotId = $params->fromPost('snapshot') ?: ($params->fromQuery('snapshot') ?: null); |
||
| 74 | |||
| 75 | if (empty($id) && empty($snapshotId) && $allowDraft) { |
||
| 76 | $this->acl->__invoke('Jobs/Manage', 'new'); |
||
| 77 | $user = $this->auth->getUser(); |
||
| 78 | /** @var \Jobs\Entity\Job $job */ |
||
| 79 | $job = $jobRepository->findDraft($user); |
||
| 80 | if (empty($job)) { |
||
| 81 | $job = $jobRepository->create(); |
||
| 82 | $job->setIsDraft(true); |
||
| 83 | $job->setUser($user); |
||
| 84 | $this->repositoryService->store($job); |
||
| 85 | } |
||
| 86 | return $job; |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($snapshotId) { |
||
| 90 | $snapshotRepo = $this->repositoryService->get('Jobs/JobSnapshot'); |
||
| 91 | $job = $snapshotRepo->find($snapshotId); |
||
| 92 | |||
| 93 | } else { |
||
| 94 | $job = $jobRepository->find($id); |
||
| 95 | if (!$job->isDraft()) { |
||
| 96 | $snapshotRepo = $this->repositoryService->get('Jobs/JobSnapshot'); |
||
| 97 | $snapshot = $snapshotRepo->findLatest($job->getId(), /*isDraft*/ true); |
||
| 98 | |||
| 99 | $job = $snapshot ?: $snapshotRepo->create($job, true); |
||
|
|
|||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if (!$job) { |
||
| 104 | throw new NotFoundException($id); |
||
| 105 | } |
||
| 106 | |||
| 107 | return $job; |
||
| 108 | } |
||
| 109 | } |
||
| 110 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.