Conditions | 6 |
Paths | 9 |
Total Lines | 52 |
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 |
||
65 | protected function configureQuery(SelectQuery $query, bool $loadColumns = true, array $outerKeys = []): SelectQuery |
||
66 | { |
||
67 | if (!empty($this->options['using'])) { |
||
68 | //Use pre-defined query |
||
69 | return parent::configureQuery($query, $loadColumns, $outerKeys); |
||
70 | } |
||
71 | |||
72 | if ($this->isJoined()) { |
||
73 | $query->join( |
||
74 | $this->getMethod() == self::JOIN ? 'INNER' : 'LEFT', |
||
75 | "{$this->getTable()} AS {$this->getAlias()}") |
||
76 | ->on( |
||
77 | $this->localKey(Record::OUTER_KEY), |
||
78 | $this->parentKey(Record::INNER_KEY) |
||
79 | ); |
||
80 | } else { |
||
81 | //This relation is loaded using external query |
||
82 | $query->where( |
||
83 | $this->localKey(Record::OUTER_KEY), |
||
84 | 'IN', |
||
85 | new Parameter($outerKeys) |
||
86 | ); |
||
87 | |||
88 | $this->configureWindow($query, $this->options['orderBy'], $this->options['limit']); |
||
89 | } |
||
90 | |||
91 | //When relation is joined we will use ON statements, when not - normal WHERE |
||
92 | $whereTarget = $this->isJoined() ? 'onWhere' : 'where'; |
||
93 | |||
94 | //Where conditions specified in relation definition |
||
95 | $this->setWhere($query, $this->getAlias(), $whereTarget, $this->schema[Record::WHERE]); |
||
96 | |||
97 | //User specified WHERE conditions |
||
98 | $this->setWhere($query, $this->getAlias(), $whereTarget, $this->options['where']); |
||
99 | |||
100 | //Morphed records |
||
101 | if (!empty($this->schema[Record::MORPH_KEY])) { |
||
102 | $this->setWhere( |
||
103 | $query, |
||
104 | $this->getAlias(), |
||
105 | $whereTarget, |
||
106 | [ |
||
107 | $this->localKey(Record::MORPH_KEY) => $this->orm->define( |
||
108 | $this->parent->getClass(), |
||
109 | ORMInterface::R_ROLE_NAME |
||
110 | ) |
||
111 | ] |
||
112 | ); |
||
113 | } |
||
114 | |||
115 | return parent::configureQuery($query, $loadColumns); |
||
116 | } |
||
117 | |||
132 | } |