Conditions | 9 |
Paths | 32 |
Total Lines | 54 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
52 | public function createSearchQuery(RaCandidateQuery $query): Query |
||
53 | { |
||
54 | $queryBuilder = $this->getBaseQuery(); |
||
55 | |||
56 | // Modify query to filter on authorization: |
||
57 | // For the RA candidates we want the identities that we could make RA. Because we then need to look at the |
||
58 | // select_raa's we have to look at the institution of the candidate because that's the institution we could |
||
59 | // select RA's from. Hence the 'rac.institution'. |
||
60 | $this->authorizationRepositoryFilter->filter( |
||
61 | $queryBuilder, |
||
62 | $query->authorizationContext, |
||
63 | 'i.institution', |
||
64 | 'iac', |
||
65 | ); |
||
66 | |||
67 | if ($query->institution) { |
||
68 | $queryBuilder |
||
69 | ->andWhere('i.institution = :institution') |
||
70 | ->setParameter('institution', $query->institution); |
||
71 | } |
||
72 | |||
73 | if ($query->commonName !== '' && $query->commonName !== '0') { |
||
74 | $queryBuilder |
||
75 | ->andWhere('i.commonName LIKE :commonName') |
||
76 | ->setParameter('commonName', sprintf('%%%s%%', $query->commonName)); |
||
77 | } |
||
78 | |||
79 | if ($query->email !== '' && $query->email !== '0') { |
||
80 | $queryBuilder |
||
81 | ->andWhere('i.email LIKE :email') |
||
82 | ->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
83 | } |
||
84 | |||
85 | if (isset($query->secondFactorTypes) && $query->secondFactorTypes !== []) { |
||
86 | $queryBuilder |
||
87 | ->andWhere('vsf.type IN (:secondFactorTypes)') |
||
88 | ->setParameter('secondFactorTypes', $query->secondFactorTypes); |
||
89 | // Self asserted tokens diminish the LoA never resulting in a valid |
||
90 | // second factor candidate. Only on-premise and self-vetted tokens |
||
91 | // can be a valid option. |
||
92 | $queryBuilder |
||
93 | ->andWhere('vsf.vettingType != :vettingType') |
||
94 | ->setParameter('vettingType', VettingType::TYPE_SELF_ASSERTED_REGISTRATION); |
||
95 | } |
||
96 | |||
97 | if (!empty($query->raInstitution)) { |
||
98 | $queryBuilder |
||
99 | ->andWhere('a.raInstitution = :raInstitution') |
||
100 | ->setParameter('raInstitution', $query->raInstitution); |
||
101 | } |
||
102 | |||
103 | $queryBuilder->groupBy('i.id'); |
||
104 | |||
105 | return $queryBuilder->getQuery(); |
||
106 | } |
||
178 |