| Conditions | 8 |
| Paths | 17 |
| Total Lines | 72 |
| 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 |
||
| 85 | public function configureQuery(SelectQuery $query, bool $loadColumns = true, array $outerKeys = []): SelectQuery |
||
| 86 | { |
||
| 87 | if (!empty($this->options['using'])) { |
||
| 88 | //Use pre-defined query |
||
| 89 | return parent::configureQuery($query, $loadColumns, $outerKeys); |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($this->isJoined()) { |
||
| 93 | $query->join( |
||
| 94 | $this->getMethod() == self::JOIN ? 'INNER' : 'LEFT', |
||
| 95 | $this->pivotTable() . ' AS ' . $this->pivotAlias()) |
||
| 96 | ->on( |
||
| 97 | $this->pivotKey(Record::THOUGHT_INNER_KEY), |
||
| 98 | $this->parentKey(Record::INNER_KEY) |
||
| 99 | ); |
||
| 100 | } else { |
||
| 101 | $query->innerJoin( |
||
| 102 | $this->pivotTable() . ' AS ' . $this->pivotAlias()) |
||
| 103 | ->on( |
||
| 104 | $this->pivotKey(Record::THOUGHT_OUTER_KEY), |
||
| 105 | $this->localKey(Record::OUTER_KEY) |
||
| 106 | )->where( |
||
| 107 | $this->pivotKey(Record::THOUGHT_INNER_KEY), |
||
| 108 | new Parameter($outerKeys) |
||
| 109 | ); |
||
| 110 | |||
| 111 | $this->configureWindow($query, $this->options['orderBy'], $this->options['limit']); |
||
| 112 | } |
||
| 113 | |||
| 114 | //When relation is joined we will use ON statements, when not - normal WHERE |
||
| 115 | $whereTarget = $this->isJoined() ? 'onWhere' : 'where'; |
||
| 116 | |||
| 117 | //Pivot conditions specified in relation schema |
||
| 118 | $this->setWhere( |
||
| 119 | $query, |
||
| 120 | $this->pivotAlias(), |
||
| 121 | $whereTarget, |
||
| 122 | $this->schema[Record::WHERE_PIVOT] |
||
| 123 | ); |
||
| 124 | |||
| 125 | //Additional morphed conditions |
||
| 126 | if (!empty($this->schema[Record::MORPH_KEY])) { |
||
| 127 | $this->setWhere( |
||
| 128 | $query, |
||
| 129 | $this->pivotAlias(), |
||
| 130 | 'onWhere', |
||
| 131 | [$this->pivotKey(Record::MORPH_KEY) => $this->targetRole()] |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | |||
| 135 | //Pivot conditions specified by user |
||
| 136 | $this->setWhere($query, $this->pivotAlias(), $whereTarget, $this->options['wherePivot']); |
||
| 137 | |||
| 138 | if ($this->isJoined()) { |
||
| 139 | //Actual data is always INNER join |
||
| 140 | $query->join( |
||
| 141 | $this->getMethod() == self::JOIN ? 'INNER' : 'LEFT', |
||
| 142 | $this->getTable() . ' AS ' . $this->getAlias() |
||
| 143 | )->on( |
||
| 144 | $this->localKey(Record::OUTER_KEY), |
||
| 145 | $this->pivotKey(Record::THOUGHT_OUTER_KEY) |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | |||
| 149 | //Where conditions specified in relation definition |
||
| 150 | $this->setWhere($query, $this->getAlias(), $whereTarget, $this->schema[Record::WHERE]); |
||
| 151 | |||
| 152 | //User specified WHERE conditions |
||
| 153 | $this->setWhere($query, $this->getAlias(), $whereTarget, $this->options['where']); |
||
| 154 | |||
| 155 | return parent::configureQuery($query, $loadColumns); |
||
| 156 | } |
||
| 157 | |||
| 272 | } |