| Conditions | 4 |
| Paths | 6 |
| Total Lines | 65 |
| Code Lines | 43 |
| 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 |
||
| 59 | public function getInstitutionsForRole(RegistrationAuthorityRole $role, IdentityId $actorId) :InstitutionCollection |
||
| 60 | { |
||
| 61 | $result = new InstitutionCollection(); |
||
| 62 | $qb = $this->_em->createQueryBuilder() |
||
| 63 | ->select("a.institution") |
||
| 64 | ->from(ConfiguredInstitution::class, 'i') |
||
| 65 | ->innerJoin(RaListing::class, 'r', Join::WITH, "i.institution = r.raInstitution") |
||
| 66 | ->innerJoin( |
||
| 67 | InstitutionAuthorization::class, |
||
| 68 | 'a', |
||
| 69 | Join::WITH, |
||
| 70 | "i.institution = a.institutionRelation AND a.institutionRole IN (:authorizationRoles)" |
||
| 71 | ) |
||
| 72 | ->where("r.identityId = :identityId AND r.role IN(:roles)") |
||
| 73 | ->groupBy("a.institution"); |
||
| 74 | |||
| 75 | $qb->setParameter('identityId', (string)$actorId); |
||
| 76 | $qb->setParameter( |
||
| 77 | 'authorizationRoles', |
||
| 78 | $this->getAllowedInstitutionRoles($role) |
||
| 79 | ); |
||
| 80 | $identityRoles = $this->getAllowedIdentityRoles($role); |
||
| 81 | $qb->setParameter( |
||
| 82 | 'roles', |
||
| 83 | $identityRoles |
||
| 84 | ); |
||
| 85 | |||
| 86 | $institutions = $qb->getQuery()->getArrayResult(); |
||
| 87 | foreach ($institutions as $institution) { |
||
| 88 | $this->logger->notice( |
||
| 89 | sprintf('Adding %s to authorized institutions', $institution['institution']) |
||
| 90 | ); |
||
| 91 | $result->add(new Institution((string)$institution['institution'])); |
||
| 92 | } |
||
| 93 | |||
| 94 | // Also get the institutions that are linked to the user via the 'institution_relation' field. |
||
| 95 | // Effectively getting the use_raa relation. |
||
| 96 | // See https://www.pivotaltracker.com/story/show/181537313 |
||
| 97 | $qb = $this->_em->createQueryBuilder() |
||
| 98 | ->select('ia.institution') |
||
| 99 | ->from(InstitutionAuthorization::class, 'ia') |
||
| 100 | // Filter the RA listing on the authorizations that apply for the RA(A) listed there |
||
| 101 | // For example, when testing a USE_RA institution authorization, the listed RA should have |
||
| 102 | // at least a RA or RAA role |
||
| 103 | ->join(RaListing::class, 'r', Join::WITH, 'r.raInstitution = ia.institutionRelation AND r.role IN (:identityRoles)') |
||
| 104 | ->where('r.identityId = :identityId') |
||
| 105 | ->andWhere("ia.institutionRole = :role") // Only filter on use_ra and use_raa roles here. |
||
| 106 | ->groupBy('ia.institution'); |
||
| 107 | |||
| 108 | $qb->setParameter('identityId', (string)$actorId); |
||
| 109 | $qb->setParameter('role', $this->getInstitutionRoleByRaRole($role)); |
||
| 110 | $qb->setParameter('identityRoles', $identityRoles); |
||
| 111 | |||
| 112 | $institutions = $qb->getQuery()->getArrayResult(); |
||
| 113 | foreach ($institutions as $institution) { |
||
| 114 | $institutionVo = new Institution((string)$institution['institution']); |
||
| 115 | if (!$result->contains($institutionVo)) { |
||
| 116 | $result->add($institutionVo); |
||
| 117 | $this->logger->notice( |
||
| 118 | sprintf('Adding %s to authorized institutions from %s', $role->getType(), $institution['institution']) |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return $result; |
||
| 124 | } |
||
| 208 |