| Conditions | 14 |
| Paths | 80 |
| Total Lines | 51 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 142 | public function query($params) |
||
| 143 | { |
||
| 144 | //convert dates to correct format |
||
| 145 | $fields = $this->parameterFields(); |
||
| 146 | $fields->setValues($params); |
||
| 147 | $start = $fields->fieldByName('StartPeriod')->dataValue(); |
||
| 148 | $end = $fields->fieldByName('EndPeriod')->dataValue(); |
||
| 149 | //include the entire end day |
||
| 150 | if ($end) { |
||
| 151 | $end = date('Y-m-d', strtotime($end) + 86400); |
||
| 152 | } |
||
| 153 | $filterperiod = $this->periodfield; |
||
| 154 | $query = new ShopReportQuery(); |
||
| 155 | $query->setSelect(['FilterPeriod' => "MIN($filterperiod)"]); |
||
| 156 | |||
| 157 | $table = DataObject::getSchema()->tableName($this->dataClass); |
||
| 158 | |||
| 159 | $query->setFrom('"' . $table . '"'); |
||
| 160 | |||
| 161 | if ($start && $end) { |
||
| 162 | $query->addWhere("$filterperiod BETWEEN '$start' AND '$end'"); |
||
| 163 | } elseif ($start) { |
||
| 164 | $query->addWhere("$filterperiod > '$start'"); |
||
| 165 | } elseif ($end) { |
||
| 166 | $query->addWhere("$filterperiod <= '$end'"); |
||
| 167 | } |
||
| 168 | if ($start || $end || !self::config()->display_uncategorised_data || !isset($params['IncludeUncategorised'])) { |
||
| 169 | $query->addWhere("$filterperiod IS NOT NULL"); |
||
| 170 | } |
||
| 171 | if ($this->grouping) { |
||
| 172 | switch ($params['Grouping']) { |
||
| 173 | case 'Year': |
||
| 174 | $query->addGroupBy($this->fd($filterperiod, '%Y')); |
||
| 175 | break; |
||
| 176 | case 'Month': |
||
| 177 | default: |
||
| 178 | $query->addGroupBy($this->fd($filterperiod, '%Y') . ',' . $this->fd($filterperiod, '%m')); |
||
| 179 | break; |
||
| 180 | case 'Day': |
||
| 181 | $query->addGroupBy( |
||
| 182 | $this->fd($filterperiod, '%Y') . ',' . $this->fd($filterperiod, '%m') . ',' . $this->fd( |
||
| 183 | $filterperiod, |
||
| 184 | '%d' |
||
| 185 | ) |
||
| 186 | ); |
||
| 187 | break; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | $query->setOrderBy('"FilterPeriod"', 'ASC'); |
||
| 191 | |||
| 192 | return $query; |
||
| 193 | } |
||
| 220 |