| Conditions | 14 |
| Paths | 208 |
| Total Lines | 63 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 62 | public function createSearchQuery(RaSecondFactorQuery $query) |
||
| 63 | { |
||
| 64 | $queryBuilder = $this |
||
| 65 | ->createQueryBuilder('sf') |
||
| 66 | ->andWhere('sf.institution = :institution') |
||
| 67 | ->setParameter('institution', $query->institution); |
||
| 68 | |||
| 69 | if ($query->name) { |
||
| 70 | $queryBuilder->andWhere('sf.name LIKE :name')->setParameter('name', sprintf('%%%s%%', $query->name)); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($query->type) { |
||
| 74 | $queryBuilder->andWhere('sf.type = :type')->setParameter('type', $query->type); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($query->secondFactorId) { |
||
| 78 | $queryBuilder |
||
| 79 | ->andWhere('sf.secondFactorId = :secondFactorId') |
||
| 80 | ->setParameter('secondFactorId', $query->secondFactorId); |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($query->email) { |
||
| 84 | $queryBuilder->andWhere('sf.email LIKE :email')->setParameter('email', sprintf('%%%s%%', $query->email)); |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($query->status) { |
||
| 88 | $stringStatus = $query->status; |
||
| 89 | if (!SecondFactorStatus::isValidStatus($stringStatus)) { |
||
| 90 | throw new RuntimeException(sprintf( |
||
| 91 | 'Received invalid status "%s" in RaSecondFactorRepository::createSearchQuery', |
||
| 92 | is_object($stringStatus) ? get_class($stringStatus) : (string) $stringStatus |
||
| 93 | )); |
||
| 94 | } |
||
| 95 | |||
| 96 | // we need to resolve the string value to database value using the correct doctrine type. Normally this is |
||
| 97 | // done by doctrine itself, however the queries PagerFanta creates somehow manages to mangle this... |
||
| 98 | // so we do it by hand |
||
| 99 | $doctrineType = Type::getType(SecondFactorStatusType::NAME); |
||
| 100 | $secondFactorStatus = SecondFactorStatus::$stringStatus(); |
||
| 101 | |||
| 102 | $databaseValue = $doctrineType->convertToDatabaseValue( |
||
| 103 | $secondFactorStatus, |
||
| 104 | $this->getEntityManager()->getConnection()->getDatabasePlatform() |
||
| 105 | ); |
||
| 106 | |||
| 107 | $queryBuilder->andWhere('sf.status = :status')->setParameter('status', $databaseValue); |
||
| 108 | } |
||
| 109 | |||
| 110 | switch ($query->orderBy) { |
||
| 111 | case 'name': |
||
| 112 | case 'type': |
||
| 113 | case 'secondFactorId': |
||
| 114 | case 'email': |
||
| 115 | case 'status': |
||
| 116 | $queryBuilder->orderBy( |
||
| 117 | sprintf('sf.%s', $query->orderBy), |
||
| 118 | $query->orderDirection === 'desc' ? 'DESC' : 'ASC' |
||
| 119 | ); |
||
| 120 | break; |
||
| 121 | } |
||
| 122 | |||
| 123 | return $queryBuilder->getQuery(); |
||
| 124 | } |
||
| 125 | |||
| 160 |
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.