Conditions | 17 |
Paths | 960 |
Total Lines | 77 |
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 |
||
91 | public function createSearchQuery(RaSecondFactorQuery $query) |
||
92 | { |
||
93 | $queryBuilder = $this |
||
94 | ->createQueryBuilder('sf'); |
||
95 | |||
96 | // Modify query to filter on authorization |
||
97 | // The SRAA user does not adhere to the FGA filter rules when searching for tokens |
||
98 | if (!$query->authorizationContext->isActorSraa()) { |
||
99 | $this->authorizationRepositoryFilter->filter( |
||
100 | $queryBuilder, |
||
101 | $query->authorizationContext, |
||
102 | 'sf.institution', |
||
103 | 'iac' |
||
104 | ); |
||
105 | } |
||
106 | |||
107 | if ($query->name) { |
||
108 | $queryBuilder->andWhere('sf.name LIKE :name')->setParameter('name', sprintf('%%%s%%', $query->name)); |
||
109 | } |
||
110 | |||
111 | if ($query->type) { |
||
112 | $queryBuilder->andWhere('sf.type = :type')->setParameter('type', $query->type); |
||
113 | } |
||
114 | |||
115 | if ($query->secondFactorId) { |
||
116 | $queryBuilder |
||
117 | ->andWhere('sf.secondFactorId = :secondFactorId') |
||
118 | ->setParameter('secondFactorId', $query->secondFactorId); |
||
119 | } |
||
120 | |||
121 | if ($query->email) { |
||
122 | $queryBuilder->andWhere('sf.email LIKE :email')->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
123 | } |
||
124 | |||
125 | if ($query->institution) { |
||
126 | $queryBuilder->andWhere('sf.institution = :institution')->setParameter('institution', $query->institution); |
||
127 | } |
||
128 | |||
129 | if ($query->status) { |
||
130 | $stringStatus = $query->status; |
||
131 | if (!SecondFactorStatus::isValidStatus($stringStatus)) { |
||
132 | throw new RuntimeException(sprintf( |
||
133 | 'Received invalid status "%s" in RaSecondFactorRepository::createSearchQuery', |
||
134 | is_object($stringStatus) ? get_class($stringStatus) : (string) $stringStatus |
||
135 | )); |
||
136 | } |
||
137 | |||
138 | // we need to resolve the string value to database value using the correct doctrine type. Normally this is |
||
139 | // done by doctrine itself, however the queries PagerFanta creates somehow manages to mangle this... |
||
140 | // so we do it by hand |
||
141 | $doctrineType = Type::getType(SecondFactorStatusType::NAME); |
||
142 | $secondFactorStatus = SecondFactorStatus::$stringStatus(); |
||
143 | |||
144 | $databaseValue = $doctrineType->convertToDatabaseValue( |
||
145 | $secondFactorStatus, |
||
146 | $this->getEntityManager()->getConnection()->getDatabasePlatform() |
||
147 | ); |
||
148 | |||
149 | $queryBuilder->andWhere('sf.status = :status')->setParameter('status', $databaseValue); |
||
150 | } |
||
151 | |||
152 | switch ($query->orderBy) { |
||
153 | case 'name': |
||
154 | case 'type': |
||
155 | case 'secondFactorId': |
||
156 | case 'email': |
||
157 | case 'institution': |
||
158 | case 'status': |
||
159 | $queryBuilder->orderBy( |
||
160 | sprintf('sf.%s', $query->orderBy), |
||
161 | $query->orderDirection === 'desc' ? 'DESC' : 'ASC' |
||
162 | ); |
||
163 | break; |
||
164 | } |
||
165 | |||
166 | return $queryBuilder->getQuery(); |
||
167 | } |
||
168 | |||
203 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.