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