Conditions | 13 |
Paths | 26 |
Total Lines | 59 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
126 | public function shortenIdList() : string |
||
127 | { |
||
128 | $finalArray = []; |
||
129 | $operator = ''; |
||
130 | $glue = 'OR'; |
||
131 | $myIDList = $this->idList; |
||
132 | $countMyIDList = count($myIDList); |
||
133 | if($countMyIDList > 0) { |
||
134 | if($this->isNumber) { |
||
135 | $otherArray = []; |
||
136 | |||
137 | //simplify select statement |
||
138 | $ranges = $this->findRanges($myIDList); |
||
139 | $rangesCount = count($ranges); |
||
140 | |||
141 | //if it is long, then see if exclude is a better solution ... |
||
142 | if($this->Config()->include_exclude_option) { |
||
143 | $excludeList = $this->excludeList(); |
||
144 | if($excludeList) { |
||
145 | $excludeRanges = $this->findRanges($excludeList); |
||
146 | if(count($excludeRanges) < $rangesCount) { |
||
147 | $ranges = $excludeRanges; |
||
148 | $glue = 'AND'; |
||
149 | $operator = 'NOT'; |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | foreach($ranges as $range) { |
||
154 | $min = min($range); |
||
155 | $max = max($range); |
||
156 | if($min === $max) { |
||
157 | $otherArray[$min] = $min; |
||
158 | } else { |
||
159 | $finalArray[] = '"'.$this->getTableName().'"."'.$this->field.'" '.$operator.' BETWEEN '.$min.' AND '.$max; |
||
160 | } |
||
161 | } |
||
162 | if(count($otherArray)) { |
||
163 | $finalArray[] = '"'.$this->getTableName().'"."'.$this->field.'" '.$operator.' IN('.implode(',', $otherArray).')'; |
||
164 | } |
||
165 | } else { |
||
166 | //if it is long, then see if exclude is a better solution ... |
||
167 | if($this->Config()->include_exclude_option) { |
||
168 | $excludeList = $this->excludeList(); |
||
169 | if($excludeList) { |
||
170 | if(count($excludeList) < $countMyIDList) { |
||
171 | $myIDList = $excludeList; |
||
172 | $glue = 'AND'; |
||
173 | $operator = 'NOT'; |
||
174 | } |
||
175 | } |
||
176 | $finalArray[] = '"'.$this->getTableName().'"."'.$this->field.'" '.$operator.' IN(\''.implode('\',\'', $myIDList).'\')'; |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | if(count($finalArray) === 0) { |
||
181 | $finalArray[] = '"'.$this->getTableName().'"."'.$this->field.'" '.$operator.' IN(-1)'; |
||
182 | } |
||
183 | |||
184 | return '('.implode(') '.$glue.' (', $finalArray).')'; |
||
185 | } |
||
267 |