Completed
Push — master ( 0f0d9a...074283 )
by Scott
02:15
created

Promotion   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 82
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A filterFields() 0 5 1
1
<?php namespace Bedard\Shop\Models;
2
3
use Model;
4
5
/**
6
 * Promotion Model.
7
 */
8
class Promotion extends Model
9
{
10
    use \Bedard\Shop\Traits\Amountable,
11
        \Bedard\Shop\Traits\StartEndable,
12
        \Bedard\Shop\Traits\Timeable,
13
        \October\Rain\Database\Traits\Purgeable,
14
        \October\Rain\Database\Traits\Validation;
15
16
    /**
17
     * @var string The database table used by the model.
18
     */
19
    public $table = 'bedard_shop_promotions';
20
21
    /**
22
     * @var array Default attributes
23
     */
24
    public $attributes = [
25
        'amount' => 0,
26
        'is_percentage' => true,
27
        'minimum_cart_value' => 0,
28
    ];
29
30
    /**
31
     * @var array Attribute casting
32
     */
33
    public $casts = [
34
        'amount' => 'float',
35
        'is_percentage' => 'boolean',
36
    ];
37
38
    /**
39
     * @var array Guarded fields
40
     */
41
    protected $guarded = ['*'];
42
43
    /**
44
     * @var array Fillable fields
45
     */
46
    protected $fillable = [
47
        'amount',
48
        'is_percentage',
49
        'message',
50
        'minimum_cart_value',
51
        'name',
52
    ];
53
54
    /**
55
     * @var array Purgeable vields
56
     */
57
    protected $purgeable = [];
58
59
    /**
60
     * @var  array Validation rules
61
     */
62
    public $rules = [
63
        'end_at' => 'date',
64
        'minimum_cart_value' => 'numeric|min:0',
65
        'name' => 'required',
66
        'start_at' => 'date',
67
    ];
68
69
    /**
70
     * @var array Relations
71
     */
72
    public $hasMany = [
73
        'carts' => [
74
            'Bedard\Shop\Models\Cart',
75
        ],
76
    ];
77
78
    /**
79
     * Filter form fields.
80
     *
81
     * @param  object   $fields
82
     * @return void
83
     */
84
    public function filterFields($fields)
85
    {
86
        $fields->amount_exact->hidden = $this->is_percentage;
87
        $fields->amount_percentage->hidden = ! $this->is_percentage;
88
    }
89
}
90