Note::closedUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Models;
10
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\SoftDeletes;
13
use GitScrum\Scopes\GlobalScope;
14
15
class Note extends Model
16
{
17
    use SoftDeletes;
18
    use GlobalScope;
19
20
    /**
21
     * The database table used by the model.
22
     *
23
     * @var string
24
     */
25
    protected $table = 'notes';
26
27
    /**
28
     * Attributes that should be mass-assignable.
29
     *
30
     * @var array
31
     */
32
    protected $fillable = ['noteable_type', 'noteable_id', 'user_id',
33
        'slug', 'title', 'position', 'closed_at', ];
34
35
    /**
36
     * The attributes excluded from the model's JSON form.
37
     *
38
     * @var array
39
     */
40
    protected $hidden = [];
41
42
    /**
43
     * The attributes that should be casted to native types.
44
     *
45
     * @var array
46
     */
47
    protected $casts = [];
48
49
    /**
50
     * The attributes that should be mutated to dates.
51
     *
52
     * @var array
53
     */
54
    protected $dates = ['deleted_at'];
55
56
    protected static function boot()
57
    {
58
        parent::boot();
59
    }
60
61
    public function noteable()
62
    {
63
        return $this->morphTo('noteable');
64
    }
65
66
    public function statuses()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
67
    {
68
        return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
69
            ->orderby('created_at', 'DESC');
70
    }
71
72
    public function closedUser()
73
    {
74
        return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id');
75
    }
76
77
    public function setClosedUserIdAttribute($value)
78
    {
79
        $this->attributes['closed_user_id'] = is_null($this->closed_at) ? $value : null;
0 ignored issues
show
Documentation introduced by
The property closed_at does not exist on object<GitScrum\Models\Note>. 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...
80
    }
81
82
    public function setClosedAtAttribute($value)
83
    {
84
        $this->attributes['closed_at'] = is_null($this->closed_at) ? $value : null;
0 ignored issues
show
Documentation introduced by
The property closed_at does not exist on object<GitScrum\Models\Note>. 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...
85
    }
86
}
87