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