Service   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 105
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A getTypeNameAttribute() 0 8 2
A business() 0 4 1
A save() 0 6 1
A setDurationAttribute() 0 4 2
A scopeSlug() 0 4 1
1
<?php
2
3
namespace Timegridio\Concierge\Models;
4
5
use Illuminate\Database\Eloquent\Model as EloquentModel;
6
7
/**
8
 * @property int $id
9
 * @property int $business_id
10
 * @property Timegridio\Concierge\Models\Business $business
11
 * @property string $name
12
 * @property string $slug
13
 * @property string $description
14
 * @property string $prerequisites
15
 * @property int $duration
16
 * @property int $type_id
17
 * @property string $color
18
 */
19
class Service extends EloquentModel
20
{
21
    /**
22
     * The attributes that are mass assignable.
23
     *
24
     * @var array
25
     */
26
    protected $fillable = [
27
        'name',
28
        'business_id',
29
        'description',
30
        'prerequisites',
31
        'duration',
32
        'type_id',
33
        'color'
34
        ];
35
36
    /**
37
     * The attributes that aren't mass assignable.
38
     *
39
     * @var array
40
     */
41
    protected $guarded = ['id', 'slug'];
42
43
    /**
44
     * Belongs to service type.
45
     *
46
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Service belongs to type query
47
     */
48 3
    public function type()
49
    {
50 3
        return $this->belongsTo(ServiceType::class);
51
    }
52
53
    /**
54
     * Get service type name.
55
     *
56
     * @return string
57
     */
58 2
    public function getTypeNameAttribute()
59
    {
60 2
        if ($this->type) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<Timegridio\Concierge\Models\Service>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61 1
            return $this->type->name;
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<Timegridio\Concierge\Models\Service>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
        }
63
64 1
        return '';
65
    }
66
67
    /**
68
     * belongs to Business.
69
     *
70
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Service belongs to Business query
71
     */
72 3
    public function business()
73
    {
74 3
        return $this->belongsTo(Business::class);
75
    }
76
77
    /**
78
     * TODO: Check slug setting can be moved to a more proper place.
79
     *
80
     * Save the model to the database.
81
     *
82
     * @param array $options
83
     *
84
     * @return bool
85
     */
86 75
    public function save(array $options = [])
87
    {
88 75
        $this->attributes['slug'] = str_slug($this->attributes['name']);
89
90 75
        return parent::save($options);
91
    }
92
93
    //////////////
94
    // Mutators //
95
    //////////////
96
97
    /**
98
     * set Duration Attribute.
99
     *
100
     * @param int $duration
101
     */
102 75
    public function setDurationAttribute($duration)
103
    {
104 75
        return $this->attributes['duration'] = $duration ? intval($duration) : null;
105
    }
106
107
    ////////////
108
    // Scopes //
109
    ////////////
110
111
    /**
112
     * Scope Slug.
113
     *
114
     * @param Illuminate\Database\Query $query
115
     * @param string                    $slug  Slug of the desired Service
116
     *
117
     * @return Illuminate\Database\Query Scoped query
118
     */
119 1
    public function scopeSlug($query, $slug)
120
    {
121 1
        return $query->where('slug', '=', $slug)->get();
122
    }
123
}
124