| Conditions | 10 |
| Paths | 320 |
| Total Lines | 64 |
| 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 |
||
| 93 | public function createSearchQuery(RaListingQuery $query) |
||
| 94 | { |
||
| 95 | $queryBuilder = $this->createQueryBuilder('r'); |
||
| 96 | |||
| 97 | // Modify query to filter on authorization |
||
| 98 | $this->authorizationRepositoryFilter->filter( |
||
| 99 | $queryBuilder, |
||
| 100 | $query->authorizationContext, |
||
| 101 | 'r.raInstitution', |
||
| 102 | 'iac' |
||
| 103 | ); |
||
| 104 | |||
| 105 | if ($query->institution) { |
||
| 106 | $queryBuilder |
||
| 107 | ->andWhere('r.institution = :institution') |
||
| 108 | ->setParameter('institution', $query->institution); |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($query->identityId) { |
||
| 112 | $queryBuilder |
||
| 113 | ->andWhere('r.identityId = :identityId') |
||
| 114 | ->setParameter('identityId', (string) $query->identityId); |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($query->name) { |
||
| 118 | $queryBuilder |
||
| 119 | ->andWhere('r.commonName LIKE :name') |
||
| 120 | ->setParameter('name', sprintf('%%%s%%', $query->name)); |
||
| 121 | } |
||
| 122 | |||
| 123 | if ($query->email) { |
||
| 124 | $queryBuilder |
||
| 125 | ->andWhere('r.email LIKE :email') |
||
| 126 | ->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($query->role) { |
||
| 130 | $queryBuilder |
||
| 131 | ->andWhere('r.role = :role') |
||
| 132 | ->setParameter('role', (string) $query->role); |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($query->raInstitution) { |
||
| 136 | $queryBuilder |
||
| 137 | ->andWhere('r.raInstitution = :raInstitution') |
||
| 138 | ->setParameter('raInstitution', (string) $query->raInstitution); |
||
| 139 | } |
||
| 140 | |||
| 141 | if (!$query->orderBy) { |
||
| 142 | return $queryBuilder->getQuery(); |
||
| 143 | } |
||
| 144 | |||
| 145 | $orderDirection = $query->orderDirection === 'asc' ? 'ASC' : 'DESC'; |
||
| 146 | |||
| 147 | switch ($query->orderBy) { |
||
| 148 | case 'commonName': |
||
| 149 | $queryBuilder->orderBy('r.commonName', $orderDirection); |
||
| 150 | break; |
||
| 151 | default: |
||
| 152 | throw new RuntimeException(sprintf('Unknown order by column "%s"', $query->orderBy)); |
||
| 153 | } |
||
| 154 | |||
| 155 | return $queryBuilder->getQuery(); |
||
| 156 | } |
||
| 157 | |||
| 222 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.