| Conditions | 4 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | public function decrementCounter( Model $model, $counter, $amount = 1, $allowNegative = FALSE ) |
||
| 39 | { |
||
| 40 | $amount = $this->getAmount( $amount, 1 ); |
||
| 41 | |||
| 42 | $currentValue = $model->{$counter}; |
||
| 43 | $final = $model->{$counter} - $amount; |
||
| 44 | |||
| 45 | if ( !$allowNegative ) |
||
| 46 | { |
||
| 47 | if ( $currentValue && $final < 0 ) |
||
| 48 | { |
||
| 49 | $model->{$counter} = 0; |
||
| 50 | $model->save(); |
||
| 51 | } |
||
| 52 | |||
| 53 | } else $model->decrement( $counter, $amount ); |
||
| 54 | |||
| 55 | return $model; |
||
| 56 | } |
||
| 68 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: