| Conditions | 19 |
| Paths | 35 |
| Total Lines | 118 |
| Lines | 54 |
| Ratio | 45.76 % |
| 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 |
||
| 160 | private function getCountFor($which) |
||
| 161 | { |
||
| 162 | try { |
||
| 163 | switch ($which) { |
||
| 164 | case self::COUNT_ALL_EVENTS: |
||
| 165 | $count = $this->event_model->count(); |
||
| 166 | break; |
||
| 167 | case self::COUNT_TICKETS: |
||
| 168 | $count = $this->ticket_model->count(); |
||
| 169 | break; |
||
| 170 | case self::COUNT_DATETIMES: |
||
| 171 | $count = $this->datetime_model->count(); |
||
| 172 | break; |
||
| 173 | case self::COUNT_ACTIVE_EVENTS: |
||
| 174 | $count = $this->event_model->get_active_events(array(), true); |
||
| 175 | break; |
||
| 176 | case self::COUNT_DATETIMES_SOLD: |
||
| 177 | $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
||
| 178 | break; |
||
| 179 | case self::COUNT_TICKETS_FREE: |
||
| 180 | $count = $this->ticket_model->count(array( |
||
| 181 | array( |
||
| 182 | 'TKT_price' => 0, |
||
| 183 | ), |
||
| 184 | )); |
||
| 185 | break; |
||
| 186 | case self::COUNT_TICKETS_PAID: |
||
| 187 | $count = $this->ticket_model->count(array( |
||
| 188 | array( |
||
| 189 | 'TKT_price' => array('>', 0), |
||
| 190 | ), |
||
| 191 | )); |
||
| 192 | break; |
||
| 193 | case self::COUNT_TICKETS_SOLD: |
||
| 194 | $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
||
| 195 | break; |
||
| 196 | case self::COUNT_REGISTRATIONS_ALL: |
||
| 197 | $count = $this->registration_model->count(); |
||
| 198 | break; |
||
| 199 | View Code Duplication | case self::COUNT_REGISTRATIONS_CANCELLED: |
|
| 200 | $count = $this->registration_model->count( |
||
| 201 | array( |
||
| 202 | array( |
||
| 203 | 'STS_ID' => EEM_Registration::status_id_cancelled, |
||
| 204 | ), |
||
| 205 | ) |
||
| 206 | ); |
||
| 207 | break; |
||
| 208 | View Code Duplication | case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
| 209 | $count = $this->registration_model->count( |
||
| 210 | array( |
||
| 211 | array( |
||
| 212 | 'STS_ID' => EEM_Registration::status_id_incomplete, |
||
| 213 | ), |
||
| 214 | ) |
||
| 215 | ); |
||
| 216 | break; |
||
| 217 | View Code Duplication | case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
| 218 | $count = $this->registration_model->count( |
||
| 219 | array( |
||
| 220 | array( |
||
| 221 | 'STS_ID' => EEM_Registration::status_id_not_approved, |
||
| 222 | ), |
||
| 223 | ) |
||
| 224 | ); |
||
| 225 | break; |
||
| 226 | View Code Duplication | case self::COUNT_REGISTRATIONS_DECLINED: |
|
| 227 | $count = $this->registration_model->count( |
||
| 228 | array( |
||
| 229 | array( |
||
| 230 | 'STS_ID' => EEM_Registration::status_id_declined, |
||
| 231 | ), |
||
| 232 | ) |
||
| 233 | ); |
||
| 234 | break; |
||
| 235 | View Code Duplication | case self::COUNT_REGISTRATIONS_PENDING: |
|
| 236 | $count = $this->registration_model->count( |
||
| 237 | array( |
||
| 238 | array( |
||
| 239 | 'STS_ID' => EEM_Registration::status_id_pending_payment, |
||
| 240 | ), |
||
| 241 | ) |
||
| 242 | ); |
||
| 243 | break; |
||
| 244 | View Code Duplication | case self::COUNT_REGISTRATIONS_APPROVED: |
|
| 245 | $count = $this->registration_model->count( |
||
| 246 | array( |
||
| 247 | array( |
||
| 248 | 'STS_ID' => EEM_Registration::status_id_approved, |
||
| 249 | ), |
||
| 250 | ) |
||
| 251 | ); |
||
| 252 | break; |
||
| 253 | case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
||
| 254 | $count = $this->transaction_model->sum( |
||
| 255 | array( |
||
| 256 | array( |
||
| 257 | 'STS_ID' => EEM_Transaction::complete_status_code, |
||
| 258 | ), |
||
| 259 | ), |
||
| 260 | 'TXN_total' |
||
| 261 | ); |
||
| 262 | break; |
||
| 263 | case self::SUM_TRANSACTIONS_ALL_PAID: |
||
| 264 | $count = $this->transaction_model->sum( |
||
| 265 | array(), |
||
| 266 | 'TXN_paid' |
||
| 267 | ); |
||
| 268 | break; |
||
| 269 | default: |
||
| 270 | $count = null; |
||
| 271 | break; |
||
| 272 | } |
||
| 273 | } catch (Exception $e) { |
||
| 274 | $count = null; |
||
| 275 | } |
||
| 276 | return $count; |
||
| 277 | } |
||
| 278 | |||
| 330 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.