| Conditions | 17 |
| Paths | 76 |
| Total Lines | 59 |
| Code Lines | 31 |
| 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 |
||
| 92 | public static function hasOrderByOnFetchJoinedToManyAssociation(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry): bool |
||
| 93 | { |
||
| 94 | if ( |
||
| 95 | 0 === \count($selectParts = $queryBuilder->getDQLPart('select')) || |
||
| 96 | 0 === \count($queryBuilder->getDQLPart('join')) || |
||
| 97 | 0 === \count($orderByParts = $queryBuilder->getDQLPart('orderBy')) |
||
| 98 | ) { |
||
| 99 | return false; |
||
| 100 | } |
||
| 101 | |||
| 102 | $rootAliases = $queryBuilder->getRootAliases(); |
||
| 103 | |||
| 104 | $selectAliases = []; |
||
| 105 | |||
| 106 | foreach ($selectParts as $select) { |
||
| 107 | foreach ($select->getParts() as $part) { |
||
| 108 | [$alias] = explode('.', $part); |
||
| 109 | |||
| 110 | $selectAliases[] = $alias; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | $selectAliases = array_diff($selectAliases, $rootAliases); |
||
| 115 | if (0 === \count($selectAliases)) { |
||
| 116 | return false; |
||
| 117 | } |
||
| 118 | |||
| 119 | $orderByAliases = []; |
||
| 120 | |||
| 121 | foreach ($orderByParts as $orderBy) { |
||
| 122 | foreach ($orderBy->getParts() as $part) { |
||
| 123 | if (false !== strpos($part, '.')) { |
||
| 124 | [$alias] = explode('.', $part); |
||
| 125 | |||
| 126 | $orderByAliases[] = $alias; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $orderByAliases = array_diff($orderByAliases, $rootAliases); |
||
| 132 | if (0 === \count($orderByAliases)) { |
||
| 133 | return false; |
||
| 134 | } |
||
| 135 | |||
| 136 | foreach ($orderByAliases as $orderByAlias) { |
||
| 137 | $inToManyContext = false; |
||
| 138 | |||
| 139 | foreach (QueryBuilderHelper::traverseJoins($orderByAlias, $queryBuilder, $managerRegistry) as $alias => [$metadata, $association]) { |
||
| 140 | if ($inToManyContext && \in_array($alias, $selectAliases, true)) { |
||
| 141 | return true; |
||
| 142 | } |
||
| 143 | |||
| 144 | if (null !== $association && $metadata->isCollectionValuedAssociation($association)) { |
||
| 145 | $inToManyContext = true; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | return false; |
||
| 151 | } |
||
| 208 |