| Conditions | 10 |
| Paths | 12 |
| Total Lines | 38 |
| Code Lines | 23 |
| 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 |
||
| 43 | public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass = null, string $operationName = null, array $context = []) |
||
| 44 | { |
||
| 45 | if (null === $resourceClass) { |
||
| 46 | throw new InvalidArgumentException('The "$resourceClass" parameter must not be null'); |
||
| 47 | } |
||
| 48 | |||
| 49 | $rootAlias = $queryBuilder->getRootAliases()[0]; |
||
| 50 | |||
| 51 | $classMetaData = $queryBuilder->getEntityManager()->getClassMetadata($resourceClass); |
||
| 52 | $identifiers = $classMetaData->getIdentifier(); |
||
| 53 | if (null !== $this->resourceMetadataFactory) { |
||
| 54 | $defaultOrder = $this->resourceMetadataFactory->create($resourceClass)->getAttribute('order'); |
||
| 55 | if (null !== $defaultOrder) { |
||
| 56 | foreach ($defaultOrder as $field => $order) { |
||
| 57 | if (\is_int($field)) { |
||
| 58 | // Default direction |
||
| 59 | $field = $order; |
||
| 60 | $order = 'ASC'; |
||
| 61 | } |
||
| 62 | |||
| 63 | $pos = strpos($field, '.'); |
||
| 64 | if (false === $pos || isset($classMetaData->embeddedClasses[\substr($field, 0, $pos)])) { |
||
| 65 | // Configure default filter with property |
||
| 66 | $field = "{$rootAlias}.{$field}"; |
||
| 67 | } else { |
||
| 68 | $alias = QueryBuilderHelper::addJoinOnce($queryBuilder, $queryNameGenerator, $rootAlias, substr($field, 0, $pos)); |
||
| 69 | $field = sprintf('%s.%s', $alias, substr($field, $pos + 1)); |
||
| 70 | } |
||
| 71 | $queryBuilder->addOrderBy($field, $order); |
||
| 72 | } |
||
| 73 | |||
| 74 | return; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if (null !== $this->order) { |
||
| 79 | foreach ($identifiers as $identifier) { |
||
| 80 | $queryBuilder->addOrderBy("{$rootAlias}.{$identifier}", $this->order); |
||
| 81 | } |
||
| 85 |