| Conditions | 12 |
| Paths | 38 |
| Total Lines | 51 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 process(Params $params,$allowDraft = true) |
||
| 63 | { |
||
| 64 | $repositories = $this->repositoryService; |
||
| 65 | $organizationRepository = $this->repositoryService->get('Organizations/Organization'); |
||
| 66 | |||
| 67 | $idFromRoute = $params('id', 0); |
||
| 68 | $idFromSubForm = $params()->fromPost('id', 0); |
||
| 69 | $user = $this->auth->getUser(); /* @var $user \Auth\Entity\UserInterface */ |
||
| 70 | |||
| 71 | /* @var $organizationId string */ |
||
| 72 | $organizationId = empty($idFromRoute)?$idFromSubForm:$idFromRoute; |
||
| 73 | |||
| 74 | $editOwnOrganization = '__my__' === $organizationId; |
||
| 75 | |||
| 76 | if ($editOwnOrganization) { |
||
| 77 | /* @var $userOrg \Organizations\Entity\OrganizationReference */ |
||
| 78 | $userOrg = $user->getOrganization(); |
||
| 79 | if ($userOrg->hasAssociation() && !$userOrg->isOwner()) { |
||
| 80 | throw new UnauthorizedAccessException('You may not edit this organization as you are only employer.'); |
||
| 81 | } |
||
| 82 | $organizationId = $userOrg->hasAssociation() ? $userOrg->getId() : 0; |
||
| 83 | } |
||
| 84 | |||
| 85 | if (empty($organizationId) && $allowDraft) { |
||
| 86 | /* @var $organization \Organizations\Entity\Organization */ |
||
| 87 | $organization = $organizationRepository->findDraft($user); |
||
| 88 | if (empty($organization)) { |
||
| 89 | $organization = $organizationRepository->create(); |
||
|
|
|||
| 90 | $organization->setIsDraft(true); |
||
| 91 | $organization->setUser($user); |
||
| 92 | if (!$editOwnOrganization) { |
||
| 93 | /* @var $parent \Organizations\Entity\OrganizationReference */ |
||
| 94 | $parent = $user->getOrganization(); |
||
| 95 | if (!$parent->hasAssociation()) { |
||
| 96 | throw new \RuntimeException('You cannot create organizations, because you do not belong to a parent organization. Use "User menu -> create my organization" first.'); |
||
| 97 | } |
||
| 98 | $organization->setParent($parent->getOrganization()); |
||
| 99 | } |
||
| 100 | |||
| 101 | $repositories->store($organization); |
||
| 102 | |||
| 103 | } |
||
| 104 | return $organization; |
||
| 105 | } |
||
| 106 | |||
| 107 | $organization = $organizationRepository->find($organizationId); |
||
| 108 | if (!$organization) { |
||
| 109 | throw new \RuntimeException('No Organization found with id "' . $organizationId . '"'); |
||
| 110 | } |
||
| 111 | return $organization; |
||
| 112 | } |
||
| 113 | } |
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.