BookableAvailability   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 84
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 BookableAvailability 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
        'from',
25
        'to',
26
        'is_bookable',
27
        'priority',
28
    ];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $casts = [
34
        'bookable_id' => 'integer',
35
        'bookable_type' => 'string',
36
        'range' => 'string',
37
        'from' => 'string',
38
        'to' => 'string',
39
        'is_bookable' => 'boolean',
40
        'priority' => 'integer',
41
    ];
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected $observables = [
47
        'validating',
48
        'validated',
49
    ];
50
51
    /**
52
     * The default rules that the model will validate against.
53
     *
54
     * @var array
55
     */
56
    protected $rules = [
57
        'bookable_id' => 'required|integer',
58
        'bookable_type' => 'required|string',
59
        'range' => 'required|in:datetimes,dates,months,weeks,days,times,sunday,monday,tuesday,wednesday,thursday,friday,saturday',
60
        'from' => 'required|string|max:150',
61
        'to' => 'required|string|max:150',
62
        'is_bookable' => 'required|boolean',
63
        'priority' => 'nullable|integer',
64
    ];
65
66
    /**
67
     * Whether the model should throw a
68
     * ValidationException if it fails validation.
69
     *
70
     * @var bool
71
     */
72
    protected $throwValidationExceptions = true;
73
74
    /**
75
     * Create a new Eloquent model instance.
76
     *
77
     * @param array $attributes
78
     */
79
    public function __construct(array $attributes = [])
80
    {
81
        parent::__construct($attributes);
82
83
        $this->setTable(config('rinvex.bookings.tables.bookable_availabilities'));
84
    }
85
86
    /**
87
     * Get the owning resource model.
88
     *
89
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
90
     */
91
    public function bookable(): MorphTo
92
    {
93
        return $this->morphTo('bookable', 'bookable_type', 'bookable_id');
94
    }
95
}
96