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