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