| Conditions | 6 |
| Paths | 32 |
| Total Lines | 66 |
| 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 |
||
| 58 | public function createSearchQuery(RaCandidateQuery $query) |
||
| 59 | { |
||
| 60 | // Base query to get all allowed ra candidates |
||
| 61 | $queryBuilder = $this->getEntityManager()->createQueryBuilder() |
||
| 62 | ->select('i.id as identity_id, i.institution, i.commonName as common_name, i.email, i.nameId AS name_id, a.institution AS ra_institution') |
||
| 63 | ->from(VettedSecondFactor::class, 'vsf') |
||
| 64 | ->innerJoin(Identity::class, 'i', Join::WITH, "vsf.identityId = i.id") |
||
| 65 | ->innerJoin(InstitutionAuthorization::class, 'a', Join::WITH, |
||
| 66 | "a.institutionRole = 'select_raa' AND a.institutionRelation = i.institution"); |
||
| 67 | |||
| 68 | // Filter out candidates who are already ra |
||
| 69 | // Todo: filter out SRAA's ? |
||
| 70 | $subQuery = $this->getEntityManager()->createQueryBuilder() |
||
| 71 | ->select('l') |
||
| 72 | ->from(RaListing::class, "l") |
||
| 73 | ->where("l.identityId = i.id AND l.raInstitution = a.institution"); |
||
| 74 | |||
| 75 | $queryBuilder->andWhere($queryBuilder->expr()->not($queryBuilder->expr()->exists($subQuery->getDQL()))); |
||
| 76 | |||
| 77 | |||
| 78 | // Modify query to filter on authorization: |
||
| 79 | // For the RA candidates we want the identities that we could make RA. Because we then need to look at the |
||
| 80 | // select_raa's we have to look at the institution of the candidate because that's the institution we could |
||
| 81 | // select RA's from. Hence the 'rac.institution'. |
||
| 82 | $this->authorizationRepositoryFilter->filter( |
||
| 83 | $queryBuilder, |
||
| 84 | $query->authorizationContext, |
||
| 85 | 'i.institution', |
||
| 86 | 'iac' |
||
| 87 | ); |
||
| 88 | |||
| 89 | if ($query->institution) { |
||
| 90 | $queryBuilder |
||
| 91 | ->andWhere('i.institution = :institution') |
||
| 92 | ->setParameter('institution', $query->institution); |
||
| 93 | } |
||
| 94 | |||
| 95 | if ($query->commonName) { |
||
| 96 | $queryBuilder |
||
| 97 | ->andWhere('i.commonName LIKE :commonName') |
||
| 98 | ->setParameter('commonName', sprintf('%%%s%%', $query->commonName)); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($query->email) { |
||
| 102 | $queryBuilder |
||
| 103 | ->andWhere('i.email LIKE :email') |
||
| 104 | ->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!empty($query->secondFactorTypes)) { |
||
| 108 | $queryBuilder |
||
| 109 | //->innerJoin(VettedSecondFactor::class, 'vsf', Join::WITH, 'rac.identityId = vsf.identityId') |
||
| 110 | ->andWhere('vsf.type IN (:secondFactorTypes)') |
||
| 111 | ->setParameter('secondFactorTypes', $query->secondFactorTypes); |
||
| 112 | } |
||
| 113 | |||
| 114 | if (!empty($query->raInstitution)) { |
||
| 115 | $queryBuilder |
||
| 116 | ->andWhere('a.raInstitution = :raInstitution') |
||
| 117 | ->setParameter('raInstitution', $query->raInstitution); |
||
| 118 | } |
||
| 119 | |||
| 120 | $queryBuilder->groupBy('i.id'); |
||
| 121 | |||
| 122 | return $queryBuilder->getQuery(); |
||
| 123 | } |
||
| 124 | |||
| 177 |