| Conditions | 19 |
| Paths | 35 |
| Total Lines | 114 |
| Code Lines | 86 |
| Lines | 54 |
| Ratio | 47.37 % |
| 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 |
||
| 151 | private function getCountFor($which) |
||
| 152 | { |
||
| 153 | try { |
||
| 154 | switch ($which) { |
||
| 155 | case self::COUNT_ALL_EVENTS: |
||
| 156 | $count = $this->event_model->count(); |
||
| 157 | break; |
||
| 158 | case self::COUNT_TICKETS: |
||
| 159 | $count = $this->ticket_model->count(); |
||
| 160 | break; |
||
| 161 | case self::COUNT_DATETIMES: |
||
| 162 | $count = $this->datetime_model->count(); |
||
| 163 | break; |
||
| 164 | case self::COUNT_ACTIVE_EVENTS: |
||
| 165 | $count = $this->event_model->get_active_events(array(), true); |
||
| 166 | break; |
||
| 167 | case self::COUNT_DATETIMES_SOLD: |
||
| 168 | $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
||
| 169 | break; |
||
| 170 | case self::COUNT_TICKETS_FREE: |
||
| 171 | $count = $this->ticket_model->count(array(array( |
||
| 172 | 'TKT_price' => 0 |
||
| 173 | ))); |
||
| 174 | break; |
||
| 175 | case self::COUNT_TICKETS_PAID: |
||
| 176 | $count = $this->ticket_model->count(array(array( |
||
| 177 | 'TKT_price' => array('>', 0) |
||
| 178 | ))); |
||
| 179 | break; |
||
| 180 | case self::COUNT_TICKETS_SOLD: |
||
| 181 | $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
||
| 182 | break; |
||
| 183 | case self::COUNT_REGISTRATIONS_ALL: |
||
| 184 | $count = $this->registration_model->count(); |
||
| 185 | break; |
||
| 186 | View Code Duplication | case self::COUNT_REGISTRATIONS_CANCELLED: |
|
| 187 | $count = $this->registration_model->count( |
||
| 188 | array( |
||
| 189 | array( |
||
| 190 | 'STS_ID' => EEM_Registration::status_id_cancelled |
||
| 191 | ) |
||
| 192 | ) |
||
| 193 | ); |
||
| 194 | break; |
||
| 195 | View Code Duplication | case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
| 196 | $count = $this->registration_model->count( |
||
| 197 | array( |
||
| 198 | array( |
||
| 199 | 'STS_ID' => EEM_Registration::status_id_incomplete |
||
| 200 | ) |
||
| 201 | ) |
||
| 202 | ); |
||
| 203 | break; |
||
| 204 | View Code Duplication | case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
| 205 | $count = $this->registration_model->count( |
||
| 206 | array( |
||
| 207 | array( |
||
| 208 | 'STS_ID' => EEM_Registration::status_id_not_approved |
||
| 209 | ) |
||
| 210 | ) |
||
| 211 | ); |
||
| 212 | break; |
||
| 213 | View Code Duplication | case self::COUNT_REGISTRATIONS_DECLINED: |
|
| 214 | $count = $this->registration_model->count( |
||
| 215 | array( |
||
| 216 | array( |
||
| 217 | 'STS_ID' => EEM_Registration::status_id_declined |
||
| 218 | ) |
||
| 219 | ) |
||
| 220 | ); |
||
| 221 | break; |
||
| 222 | View Code Duplication | case self::COUNT_REGISTRATIONS_PENDING: |
|
| 223 | $count = $this->registration_model->count( |
||
| 224 | array( |
||
| 225 | array( |
||
| 226 | 'STS_ID' => EEM_Registration::status_id_pending_payment |
||
| 227 | ) |
||
| 228 | ) |
||
| 229 | ); |
||
| 230 | break; |
||
| 231 | View Code Duplication | case self::COUNT_REGISTRATIONS_APPROVED: |
|
| 232 | $count = $this->registration_model->count( |
||
| 233 | array( |
||
| 234 | array( |
||
| 235 | 'STS_ID' => EEM_Registration::status_id_approved |
||
| 236 | ) |
||
| 237 | ) |
||
| 238 | ); |
||
| 239 | break; |
||
| 240 | case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
||
| 241 | $count = $this->transaction_model->sum( |
||
| 242 | array( |
||
| 243 | array( |
||
| 244 | 'STS_ID' => EEM_Transaction::complete_status_code |
||
| 245 | ) |
||
| 246 | ), |
||
| 247 | 'TXN_total' |
||
| 248 | ); |
||
| 249 | break; |
||
| 250 | case self::SUM_TRANSACTIONS_ALL_PAID: |
||
| 251 | $count = $this->transaction_model->sum( |
||
| 252 | array(), |
||
| 253 | 'TXN_paid' |
||
| 254 | ); |
||
| 255 | break; |
||
| 256 | default: |
||
| 257 | $count = null; |
||
| 258 | break; |
||
| 259 | } |
||
| 260 | } catch (Exception $e) { |
||
| 261 | $count = null; |
||
| 262 | } |
||
| 263 | return $count; |
||
| 264 | } |
||
| 265 | |||
| 297 | } |
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.