| Conditions | 19 |
| Paths | 91 |
| Total Lines | 67 |
| Code Lines | 35 |
| 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 | !($selectParts = $queryBuilder->getDQLPart('select')) || |
||
| 96 | !$queryBuilder->getDQLPart('join') || |
||
| 97 | !($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 | if (!$selectAliases) { |
||
| 115 | return false; |
||
| 116 | } |
||
| 117 | |||
| 118 | $selectAliases = array_diff($selectAliases, $rootAliases); |
||
| 119 | if (!$selectAliases) { |
||
|
|
|||
| 120 | return false; |
||
| 121 | } |
||
| 122 | |||
| 123 | $orderByAliases = []; |
||
| 124 | |||
| 125 | foreach ($orderByParts as $orderBy) { |
||
| 126 | foreach ($orderBy->getParts() as $part) { |
||
| 127 | if (false !== strpos($part, '.')) { |
||
| 128 | [$alias] = explode('.', $part); |
||
| 129 | |||
| 130 | $orderByAliases[] = $alias; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | if (!$orderByAliases) { |
||
| 136 | return false; |
||
| 137 | } |
||
| 138 | |||
| 139 | $orderByAliases = array_diff($orderByAliases, $rootAliases); |
||
| 140 | if (!$orderByAliases) { |
||
| 141 | return false; |
||
| 142 | } |
||
| 143 | |||
| 144 | foreach ($orderByAliases as $orderByAlias) { |
||
| 145 | $inToManyContext = false; |
||
| 146 | |||
| 147 | foreach (QueryBuilderHelper::traverseJoins($orderByAlias, $queryBuilder, $managerRegistry) as $alias => [$metadata, $association]) { |
||
| 148 | if ($inToManyContext && \in_array($alias, $selectAliases, true)) { |
||
| 149 | return true; |
||
| 150 | } |
||
| 151 | |||
| 152 | if (null !== $association && $metadata->isCollectionValuedAssociation($association)) { |
||
| 153 | $inToManyContext = true; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | return false; |
||
| 159 | } |
||
| 233 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.