Completed
Push — develop ( 5e62e3...eaaeda )
by Abdelrahman
01:05
created

Availability   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 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
use Rinvex\Bookings\Contracts\AvailabilityContract;
12
13
/**
14
 * Rinvex\Bookings\Models\Availability.
15
 *
16
 * @property int                                                $id
17
 * @property int                                                $bookable_id
18
 * @property string                                             $bookable_type
19
 * @property string                                             $day
20
 * @property \Carbon\Carbon                                     $starts_at
21
 * @property \Carbon\Carbon                                     $ends_at
22
 * @property float                                              $price
23
 * @property \Carbon\Carbon|null                                $created_at
24
 * @property \Carbon\Carbon|null                                $updated_at
25
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $bookable
26
 *
27
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereBookableId($value)
28
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereBookableType($value)
29
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereCreatedAt($value)
30
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereDay($value)
31
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereEndsAt($value)
32
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereId($value)
33
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability wherePrice($value)
34
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereStartsAt($value)
35
 * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Bookings\Models\Availability whereUpdatedAt($value)
36
 * @mixin \Eloquent
37
 */
38
class Availability extends Model implements AvailabilityContract
39
{
40
    use ValidatingTrait;
41
    use CacheableEloquent;
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected $fillable = [
47
        'bookable_id',
48
        'bookable_type',
49
        'day',
50
        'starts_at',
51
        'ends_at',
52
        'price',
53
    ];
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected $casts = [
59
        'bookable_id' => 'integer',
60
        'bookable_type' => 'string',
61
        'day' => 'string',
62
        'starts_at' => 'datetime',
63
        'ends_at' => 'datetime',
64
        'price' => 'float',
65
    ];
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    protected $observables = [
71
        'validating',
72
        'validated',
73
    ];
74
75
    /**
76
     * The default rules that the model will validate against.
77
     *
78
     * @var array
79
     */
80
    protected $rules = [];
81
82
    /**
83
     * Whether the model should throw a
84
     * ValidationException if it fails validation.
85
     *
86
     * @var bool
87
     */
88
    protected $throwValidationExceptions = true;
89
90
    /**
91
     * Create a new Eloquent model instance.
92
     *
93
     * @param array $attributes
94
     */
95
    public function __construct(array $attributes = [])
96
    {
97
        parent::__construct($attributes);
98
99
        $this->setTable(config('rinvex.bookings.tables.availabilities'));
100
        $this->setRules([
101
            'bookable_id' => 'required|integer',
102
            'bookable_type' => 'required|string',
103
            'day' => 'in:sun,mon,tue,wed,thu,fri,sat',
104
            'starts_at' => 'nullable|time',
105
            'ends_at' => 'nullable|time',
106
            'price' => 'nullable|numeric',
107
        ]);
108
    }
109
110
    /**
111
     * Get the owning model.
112
     *
113
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
114
     */
115
    public function bookable(): MorphTo
116
    {
117
        return $this->morphTo();
118
    }
119
}
120