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