| Conditions | 1 |
| Paths | 1 |
| Total Lines | 25 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace Bedard\Shop\Traits; |
||
| 10 | public static function bootAmountable() |
||
| 11 | { |
||
| 12 | static::extend(function ($model) { |
||
| 13 | $model->rules = array_merge($model->rules, [ |
||
| 14 | 'amount_exact' => 'numeric|min:0', |
||
| 15 | 'amount_percentage' => 'numeric|min:0|max:100', |
||
| 16 | ]); |
||
| 17 | |||
| 18 | $model->purgeable = array_merge($model->purgeable, [ |
||
| 19 | 'amount_exact', |
||
| 20 | 'amount_percentage', |
||
| 21 | ]); |
||
| 22 | |||
| 23 | $model->attributes = array_merge($model->attributes, [ |
||
| 24 | 'amount_exact' => 0, |
||
| 25 | 'amount_percentage' => 0, |
||
| 26 | ]); |
||
| 27 | |||
| 28 | $model->addFillable('amount_exact', 'amount_percentage'); |
||
| 29 | |||
| 30 | $model->bindEvent('model.beforeSave', function () use ($model) { |
||
| 31 | $model->setAmount(); |
||
| 32 | }); |
||
| 33 | }); |
||
| 34 | } |
||
| 35 | |||
| 71 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: