Completed
Push — develop ( 714b37...8cdca7 )
by Abdelrahman
04:46
created

Rate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 79
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A resource() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Bookings\Models;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Rinvex\Cacheable\CacheableEloquent;
9
use Rinvex\Support\Traits\ValidatingTrait;
10
use Rinvex\Bookings\Contracts\RateContract;
11
use Illuminate\Database\Eloquent\Relations\MorphTo;
12
13
/**
14
 * Rinvex\Bookings\Models\Rate.
15
 *
16
 * @property int                                                $id
17
 * @property int                                                $resource_id
18
 * @property string                                             $resource_type
19
 * @property int                                                $percentage
20
 * @property string                                             $operator
21
 * @property int                                                $amount
22
 * @property \Carbon\Carbon|null                                $created_at
23
 * @property \Carbon\Carbon|null                                $updated_at
24
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $resource
25
 *
26
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereAmount($value)
27
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereCreatedAt($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereId($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereOperator($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate wherePercentage($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereResourceId($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereResourceType($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Rate whereUpdatedAt($value)
34
 * @mixin \Eloquent
35
 */
36
class Rate extends Model implements RateContract
37
{
38
    use ValidatingTrait;
39
    use CacheableEloquent;
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected $fillable = [
45
        'resource_id',
46
        'resource_type',
47
        'percentage',
48
        'operator',
49
        'amount',
50
    ];
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected $casts = [
56
        'resource_id' => 'integer',
57
        'resource_type' => 'string',
58
        'percentage' => 'float',
59
        'operator' => 'string',
60
        'amount' => 'integer',
61
    ];
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    protected $observables = [
67
        'validating',
68
        'validated',
69
    ];
70
71
    /**
72
     * The default rules that the model will validate against.
73
     *
74
     * @var array
75
     */
76
    protected $rules = [];
77
78
    /**
79
     * Whether the model should throw a
80
     * ValidationException if it fails validation.
81
     *
82
     * @var bool
83
     */
84
    protected $throwValidationExceptions = true;
85
86
    /**
87
     * Create a new Eloquent model instance.
88
     *
89
     * @param array $attributes
90
     */
91
    public function __construct(array $attributes = [])
92
    {
93
        parent::__construct($attributes);
94
95
        $this->setTable(config('rinvex.bookings.tables.rates'));
96
        $this->setRules([
97
            'resource_id' => 'required|integer',
98
            'resource_type' => 'required|string',
99
            'percentage' => 'required|numeric|min:-100|max:100',
100
            'operator' => 'required|string|in:^,<,>,=',
101
            'amount' => 'required|integer|max:10000000',
102
        ]);
103
    }
104
105
    /**
106
     * Get the owning resource model.
107
     *
108
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
109
     */
110
    public function resource(): MorphTo
111
    {
112
        return $this->morphTo();
113
    }
114
}
115