| Conditions | 11 |
| Paths | 13 |
| Total Lines | 43 |
| 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 |
||
| 115 | public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry): bool |
||
| 116 | { |
||
| 117 | if ( |
||
| 118 | empty($orderByParts = $queryBuilder->getDQLPart('orderBy')) || |
||
| 119 | empty($joinParts = $queryBuilder->getDQLPart('join')) |
||
| 120 | ) { |
||
| 121 | return false; |
||
| 122 | } |
||
| 123 | |||
| 124 | $orderByAliases = []; |
||
| 125 | foreach ($orderByParts as $orderBy) { |
||
| 126 | $parts = QueryJoinParser::getOrderByParts($orderBy); |
||
| 127 | |||
| 128 | foreach ($parts as $part) { |
||
| 129 | if (false !== ($pos = strpos($part, '.'))) { |
||
| 130 | $alias = substr($part, 0, $pos); |
||
| 131 | |||
| 132 | $orderByAliases[$alias] = true; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | if (!empty($orderByAliases)) { |
||
| 138 | foreach ($joinParts as $joins) { |
||
| 139 | foreach ($joins as $join) { |
||
| 140 | $alias = QueryJoinParser::getJoinAlias($join); |
||
| 141 | |||
| 142 | if (isset($orderByAliases[$alias])) { |
||
| 143 | $relationship = QueryJoinParser::getJoinRelationship($join); |
||
| 144 | list($parentAlias, $association) = explode('.', $relationship); |
||
| 145 | |||
| 146 | $parentMetadata = QueryJoinParser::getClassMetadataFromJoinAlias($parentAlias, $queryBuilder, $managerRegistry); |
||
| 147 | |||
| 148 | if ($parentMetadata->isCollectionValuedAssociation($association)) { |
||
| 149 | return true; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | return false; |
||
| 157 | } |
||
| 158 | } |
||
| 159 |