Changeset View
Changeset View
Standalone View
Standalone View
src/app/Discount.php
Show All 34 Lines | class Discount extends Model | ||||
* Discount value mutator | * Discount value mutator | ||||
* | * | ||||
* @throws \Exception | * @throws \Exception | ||||
*/ | */ | ||||
public function setDiscountAttribute($discount) | public function setDiscountAttribute($discount) | ||||
{ | { | ||||
$discount = (int) $discount; | $discount = (int) $discount; | ||||
if ($discount < 0 || $discount > 100) { | if ($discount < 0) { | ||||
throw new \Exception("Invalid discount value, expected integer in range of 0-100"); | \Log::warning("Expecting a discount rate >= 0"); | ||||
$discount = 0; | |||||
} | |||||
if ($discount > 100) { | |||||
\Log::warning("Expecting a discount rate <= 100"); | |||||
$discount = 100; | |||||
machniak: We already have tests that expected an exception to be thrown. I think an exception would be… | |||||
Done Inline ActionsThere's values in the HKCCP that go out of bounds, an exception would either need to be addressed there, as well as in every future interface, or just here. I'll fix the test though. vanmeeuwen: There's values in the HKCCP that go out of bounds, an exception would either need to be… | |||||
} | } | ||||
$this->attributes['discount'] = $discount; | $this->attributes['discount'] = $discount; | ||||
} | } | ||||
/** | /** | ||||
* List of wallets with this discount assigned. | * List of wallets with this discount assigned. | ||||
* | * | ||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||||
*/ | */ | ||||
public function wallets() | public function wallets() | ||||
{ | { | ||||
return $this->hasMany('App\Wallet'); | return $this->hasMany('App\Wallet'); | ||||
} | } | ||||
} | } |
We already have tests that expected an exception to be thrown. I think an exception would be better.