| Conditions | 7 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 32 |
| 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 |
||
| 118 | public function configureQuery(SelectQuery $query, array $outerKeys = []): SelectQuery |
||
| 119 | { |
||
| 120 | if ($this->isLoaded() && $this->isJoined() && (int) $query->getLimit() !== 0) { |
||
| 121 | throw new LoaderException('Unable to load data using join with limit on parent query'); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($this->options['using'] !== null) { |
||
| 125 | // use pre-defined query |
||
| 126 | return parent::configureQuery($this->pivot->configureQuery($query), $outerKeys); |
||
| 127 | } |
||
| 128 | |||
| 129 | // Manually join pivoted table |
||
| 130 | if ($this->isJoined()) { |
||
| 131 | $query->join( |
||
| 132 | $this->getJoinMethod(), |
||
| 133 | $this->pivot->getJoinTable() |
||
| 134 | )->on( |
||
| 135 | $this->pivot->localKey(Relation::THROUGH_INNER_KEY), |
||
| 136 | $this->parentKey(Relation::INNER_KEY) |
||
| 137 | ); |
||
| 138 | |||
| 139 | $query->innerJoin( |
||
| 140 | $this->getJoinTable() |
||
| 141 | )->on( |
||
| 142 | $this->localKey(Relation::OUTER_KEY), |
||
| 143 | $this->pivot->localKey(Relation::THROUGH_OUTER_KEY) |
||
| 144 | ); |
||
| 145 | } else { |
||
| 146 | // reset all the columns when query is isolated (we have to do it manually |
||
| 147 | // since underlying loader believes it's loaded) |
||
| 148 | $query->columns([]); |
||
| 149 | |||
| 150 | $query->innerJoin( |
||
| 151 | $this->pivot->getJoinTable() |
||
| 152 | )->on( |
||
| 153 | $this->pivot->localKey(Relation::THROUGH_OUTER_KEY), |
||
| 154 | $this->localKey(Relation::OUTER_KEY) |
||
| 155 | )->where( |
||
| 156 | $this->pivot->localKey(Relation::THROUGH_INNER_KEY), |
||
| 157 | new Parameter($outerKeys) |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | |||
| 161 | // user specified WHERE conditions |
||
| 162 | $this->setWhere( |
||
| 163 | $query, |
||
| 164 | $this->getAlias(), |
||
| 165 | $this->isJoined() ? 'onWhere' : 'where', |
||
| 166 | $this->options['where'] ?? $this->schema[Relation::WHERE] ?? [] |
||
| 167 | ); |
||
| 168 | |||
| 169 | return parent::configureQuery($this->pivot->configureQuery($query)); |
||
| 170 | } |
||
| 227 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.