| Conditions | 7 |
| Paths | 4 |
| Total Lines | 61 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 126 | public function configureQuery(SelectQuery $query, array $outerKeys = []): SelectQuery |
||
| 127 | { |
||
| 128 | if ($this->isLoaded() && $this->isJoined() && (int) $query->getLimit() !== 0) { |
||
| 129 | throw new LoaderException('Unable to load data using join with limit on parent query'); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($this->options['using'] !== null) { |
||
| 133 | // use pre-defined query |
||
| 134 | return parent::configureQuery($this->pivot->configureQuery($query), $outerKeys); |
||
| 135 | } |
||
| 136 | |||
| 137 | // Manually join pivoted table |
||
| 138 | if ($this->isJoined()) { |
||
| 139 | $query->join( |
||
| 140 | $this->getJoinMethod(), |
||
| 141 | $this->pivot->getJoinTable() |
||
| 142 | )->on( |
||
| 143 | $this->pivot->localKey(Relation::THROUGH_INNER_KEY), |
||
| 144 | $this->parentKey(Relation::INNER_KEY) |
||
| 145 | ); |
||
| 146 | |||
| 147 | $query->join( |
||
| 148 | $this->getJoinMethod(), |
||
| 149 | $this->getJoinTable() |
||
| 150 | )->on( |
||
| 151 | $this->localKey(Relation::OUTER_KEY), |
||
| 152 | $this->pivot->localKey(Relation::THROUGH_OUTER_KEY) |
||
| 153 | ); |
||
| 154 | } else { |
||
| 155 | // reset all the columns when query is isolated (we have to do it manually |
||
| 156 | // since underlying loader believes it's loaded) |
||
| 157 | $query->columns([]); |
||
| 158 | |||
| 159 | $query->join( |
||
| 160 | $this->getJoinMethod(), |
||
| 161 | $this->pivot->getJoinTable() |
||
| 162 | )->on( |
||
| 163 | $this->pivot->localKey(Relation::THROUGH_OUTER_KEY), |
||
| 164 | $this->localKey(Relation::OUTER_KEY) |
||
| 165 | )->where( |
||
|
|
|||
| 166 | $this->pivot->localKey(Relation::THROUGH_INNER_KEY), |
||
| 167 | new Parameter($outerKeys) |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | |||
| 171 | // user specified WHERE conditions |
||
| 172 | $this->setWhere( |
||
| 173 | $query, |
||
| 174 | $this->getAlias(), |
||
| 175 | $this->isJoined() ? 'onWhere' : 'where', |
||
| 176 | $this->options['where'] ?? $this->schema[Relation::WHERE] ?? [] |
||
| 177 | ); |
||
| 178 | |||
| 179 | // user specified ORDER_BY rules |
||
| 180 | $this->setOrderBy( |
||
| 181 | $query, |
||
| 182 | $this->getAlias(), |
||
| 183 | $this->options['orderBy'] ?? $this->schema[Relation::ORDER_BY] ?? [] |
||
| 184 | ); |
||
| 185 | |||
| 186 | return parent::configureQuery($this->pivot->configureQuery($query)); |
||
| 187 | } |
||
| 251 |