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