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