| Conditions | 14 |
| Paths | 208 |
| 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 |
||
| 81 | public function createSearchQuery(RaSecondFactorQuery $query) |
||
| 82 | { |
||
| 83 | $queryBuilder = $this |
||
| 84 | ->createQueryBuilder('sf'); |
||
| 85 | |||
| 86 | // Modify query to filter on authorization |
||
| 87 | $this->authorizationRepositoryFilter->filter($queryBuilder, $query->authorizationContext, 'sf.id', 'sf.institution', 'iac'); |
||
| 88 | |||
| 89 | if ($query->name) { |
||
| 90 | $queryBuilder->andWhere('sf.name LIKE :name')->setParameter('name', sprintf('%%%s%%', $query->name)); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($query->type) { |
||
| 94 | $queryBuilder->andWhere('sf.type = :type')->setParameter('type', $query->type); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($query->secondFactorId) { |
||
| 98 | $queryBuilder |
||
| 99 | ->andWhere('sf.secondFactorId = :secondFactorId') |
||
| 100 | ->setParameter('secondFactorId', $query->secondFactorId); |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($query->email) { |
||
| 104 | $queryBuilder->andWhere('sf.email LIKE :email')->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($query->status) { |
||
| 108 | $stringStatus = $query->status; |
||
| 109 | if (!SecondFactorStatus::isValidStatus($stringStatus)) { |
||
| 110 | throw new RuntimeException(sprintf( |
||
| 111 | 'Received invalid status "%s" in RaSecondFactorRepository::createSearchQuery', |
||
| 112 | is_object($stringStatus) ? get_class($stringStatus) : (string) $stringStatus |
||
| 113 | )); |
||
| 114 | } |
||
| 115 | |||
| 116 | // we need to resolve the string value to database value using the correct doctrine type. Normally this is |
||
| 117 | // done by doctrine itself, however the queries PagerFanta creates somehow manages to mangle this... |
||
| 118 | // so we do it by hand |
||
| 119 | $doctrineType = Type::getType(SecondFactorStatusType::NAME); |
||
| 120 | $secondFactorStatus = SecondFactorStatus::$stringStatus(); |
||
| 121 | |||
| 122 | $databaseValue = $doctrineType->convertToDatabaseValue( |
||
| 123 | $secondFactorStatus, |
||
| 124 | $this->getEntityManager()->getConnection()->getDatabasePlatform() |
||
| 125 | ); |
||
| 126 | |||
| 127 | $queryBuilder->andWhere('sf.status = :status')->setParameter('status', $databaseValue); |
||
| 128 | } |
||
| 129 | |||
| 130 | switch ($query->orderBy) { |
||
| 131 | case 'name': |
||
| 132 | case 'type': |
||
| 133 | case 'secondFactorId': |
||
| 134 | case 'email': |
||
| 135 | case 'status': |
||
| 136 | $queryBuilder->orderBy( |
||
| 137 | sprintf('sf.%s', $query->orderBy), |
||
| 138 | $query->orderDirection === 'desc' ? 'DESC' : 'ASC' |
||
| 139 | ); |
||
| 140 | break; |
||
| 141 | } |
||
| 142 | |||
| 143 | return $queryBuilder->getQuery(); |
||
| 144 | } |
||
| 145 | |||
| 180 |
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 theSoncalls the wrong method in the parent class.