Completed
Push — develop ( 3de1d7...233a23 )
by Abdelrahman
01:42
created

BookableRate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A bookable() 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 Illuminate\Database\Eloquent\Relations\MorphTo;
11
12
abstract class BookableRate extends Model
13
{
14
    use ValidatingTrait;
15
    use CacheableEloquent;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $fillable = [
21
        'bookable_id',
22
        'bookable_type',
23
        'range',
24
        'range_from',
25
        'range_to',
26
        'base_cost',
27
        'base_cost_modifier',
28
        'unit_cost',
29
        'unit_cost_modifier',
30
        'priority',
31
    ];
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected $casts = [
37
        'bookable_id' => 'integer',
38
        'bookable_type' => 'string',
39
        'range' => 'string',
40
        'range_from' => 'string',
41
        'range_to' => 'string',
42
        'base_cost' => 'float',
43
        'base_cost_modifier' => 'string',
44
        'unit_cost' => 'float',
45
        'unit_cost_modifier' => 'string',
46
        'priority' => 'integer',
47
    ];
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected $observables = [
53
        'validating',
54
        'validated',
55
    ];
56
57
    /**
58
     * The default rules that the model will validate against.
59
     *
60
     * @var array
61
     */
62
    protected $rules = [
63
        'bookable_id' => 'required|integer',
64
        'bookable_type' => 'required|string',
65
        'range' => 'required|string|in:unit,date,month,week,day,datetime,time,time-sun,time-mon,time-tue,time-wed,time-thu,time-fri,time-sat',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
66
        'range_from' => 'required|string|max:150',
67
        'range_to' => 'required|string|max:150',
68
        'base_cost' => 'required|numeric',
69
        'base_cost_modifier' => 'required|string|in:+,-,×,÷',
70
        'unit_cost' => 'required|numeric',
71
        'unit_cost_modifier' => 'required|string|in:+,-,×,÷',
72
        'priority' => 'nullable|integer',
73
    ];
74
75
    /**
76
     * Whether the model should throw a
77
     * ValidationException if it fails validation.
78
     *
79
     * @var bool
80
     */
81
    protected $throwValidationExceptions = true;
82
83
    /**
84
     * Create a new Eloquent model instance.
85
     *
86
     * @param array $attributes
87
     */
88
    public function __construct(array $attributes = [])
89
    {
90
        parent::__construct($attributes);
91
92
        $this->setTable(config('rinvex.bookings.tables.bookable_rates'));
93
    }
94
95
    /**
96
     * Get the owning resource model.
97
     *
98
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
99
     */
100
    public function bookable(): MorphTo
101
    {
102
        return $this->morphTo('bookable', 'bookable_type', 'bookable_id');
103
    }
104
}
105