GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 321516...5ae950 )
by Nikhil
08:33
created

Purchase   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 208
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 38.46%

Importance

Changes 11
Bugs 1 Features 6
Metric Value
wmc 17
c 11
b 1
f 6
lcom 1
cbo 5
dl 0
loc 208
rs 10
ccs 15
cts 39
cp 0.3846

15 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeDelivered() 0 4 1
A scopeStored() 0 4 1
A scopePendingStorage() 0 4 1
A getStatusAttribute() 0 11 3
A isPendingStorage() 0 4 1
A guitars() 0 4 1
A getStoredAttribute() 0 4 1
A getPendingStorageAttribute() 0 4 1
A getSoldAttribute() 0 4 1
A hasArrived() 0 4 1
A isStatus() 0 4 1
A supplier() 0 4 1
A make() 0 4 1
A notifications() 0 4 1
A makeNotification() 0 12 1
1
<?php
2
3
namespace App;
4
5
use App\Events\NotificationWasCreated;
6
use Carbon\Carbon;
7
use Illuminate\Database\Eloquent;
8
use Illuminate\Support\Facades\DB;
9
10
class Purchase extends Eloquent\Model
11
{
12
    const UPCOMING = 'upcoming';
13
    const DELIVERED = 'delivered';
14
    const COMPLETED = 'completed';
15
16
    use Eloquent\SoftDeletes;
17
18
    /**
19
     * We do not want any timestamps.
20
     *
21
     * @var bool
22
     */
23
    public $timestamps = false;
24
25
    /**
26
     * The attributes that are not mass assignable.
27
     *
28
     * @var array
29
     */
30
    protected $guarded = [];
31
32
    /**
33
     * Date mutators.
34
     *
35
     * @var array
36
     */
37
    protected $dates = ['date_purchased', 'delivery_date', 'deleted_at'];
38
39
    /**
40
     * Default date format.
41
     *
42
     * @var string
43
     */
44
    protected $dateFormat = 'Y-m-d';
45
46
    /**
47
     * Delivered Scope.
48
     *
49
     * @param $query
50
     *
51
     * @return Eloquent\Builder
52
     */
53
    public function scopeDelivered($query)
54
    {
55
        return $query->where('delivery_date', '<=', Carbon::today());
56
    }
57
58
    /**
59
     * Stored Scope.
60
     *
61
     * @param $query
62
     *
63
     * @return Eloquent\Builder
64
     */
65
    public function scopeStored($query)
66
    {
67
        return $query->has('guitars', '=', DB::raw('quantity'));
68
    }
69
70
    /**
71
     * Pending Storage scope.
72
     *
73
     * @param $query
74
     *
75
     * @return Eloquent\Builder
76
     */
77
    public function scopePendingStorage($query)
78
    {
79
        return $query->has('guitars', '<', DB::raw('quantity'));
80
    }
81
82
    /**
83
     * Get status attribute.
84
     *
85
     * @return string
86
     */
87 2
    public function getStatusAttribute()
88
    {
89 2
        if ($this->delivery_date->isFuture()) {
0 ignored issues
show
Documentation introduced by
The property delivery_date does not exist on object<App\Purchase>. 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...
90 2
            return self::UPCOMING;
91
        }
92
        if ( ! $this->isPendingStorage()) {
93
            return self::COMPLETED;
94
        }
95
96
        return self::DELIVERED;
97
    }
98
99
    /**
100
     * Has Guitars Pending Storage?
101
     *
102
     * @return bool
103
     */
104
    public function isPendingStorage()
105
    {
106
        return $this->guitars()->count() < $this->quantity;
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<App\Purchase>. 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...
107
    }
108
109
    /**
110
     * Guitars bought.
111
     *
112
     * @return Eloquent\Relations\HasMany
113
     */
114 1
    public function guitars()
115
    {
116 1
        return $this->hasMany(Guitar::class);
117
    }
118
119
    /**
120
     * Storage attribute.
121
     *
122
     * @return int
123
     */
124 1
    public function getStoredAttribute()
125
    {
126 1
        return $this->guitars()->count();
127
    }
128
129
    /**
130
     * Pending Storage attribute.
131
     *
132
     * @return int
133
     */
134
    public function getPendingStorageAttribute()
135
    {
136
        return $this->quantity - $this->stored;
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<App\Purchase>. 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...
Documentation introduced by
The property stored does not exist on object<App\Purchase>. 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...
137
    }
138
139
    /**
140
     * Number of Guitars Sold.
141
     *
142
     * @return int
143
     */
144 1
    public function getSoldAttribute()
145
    {
146 1
        return $this->guitars()->sold()->count();
147
    }
148
149
    /**
150
     * Whether the purchase has arrived.
151
     *
152
     * @return bool
153
     */
154 1
    public function hasArrived()
155
    {
156 1
        return $this->isStatus(self::DELIVERED);
157
    }
158
159
    /**
160
     * Verify the status.
161
     *
162
     * @param $status
163
     *
164
     * @return bool
165
     */
166 1
    public function isStatus($status)
167
    {
168 1
        return $this->status == $status;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<App\Purchase>. 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...
169
    }
170
171
    /**
172
     * Supplier from which guitars were bought.
173
     *
174
     * @return Eloquent\Relations\BelongsTo
175
     */
176
    public function supplier()
177
    {
178
        return $this->belongsTo(Supplier::class);
179
    }
180
181
    /**
182
     * Make of the guitars.
183
     *
184
     * @return Eloquent\Relations\BelongsTo
185
     */
186 1
    public function make()
187
    {
188 1
        return $this->belongsTo(Make::class);
189
    }
190
191
    /**
192
     * Notifications about the purchase.
193
     *
194
     * @return Eloquent\Relations\MorphMany
195
     */
196
    public function notifications()
197
    {
198
        return $this->morphMany(Notification::class, 'notifiable');
199
    }
200
201
    /**
202
     * Create a new notification.
203
     * @return Notification
204
     */
205
    public function makeNotification()
206
    {
207
        $notification = $this->notifications()->create([
208
            'icon'    => 'flight_land',
209
            'link'    => '/purchases/' . $this->id,
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Purchase>. 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...
210
            'message' => "Purchase of {$this->quantity} {$this->make->name} has arrived from {$this->supplier->name}, {$this->supplier->location}.",
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<App\Purchase>. 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...
Documentation introduced by
The property make does not exist on object<App\Purchase>. 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...
Documentation introduced by
The property supplier does not exist on object<App\Purchase>. 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...
211
        ]);
212
213
        event(new NotificationWasCreated($notification));
0 ignored issues
show
Compatibility introduced by
$notification of type object<Illuminate\Database\Eloquent\Model> is not a sub-type of object<App\Notification>. It seems like you assume a child class of the class Illuminate\Database\Eloquent\Model to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
214
215
        return $notification;
216
    }
217
}
218