Completed
Pull Request — master (#29)
by Marcos
02:37
created

Note::setClosedAtAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
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
namespace GitScrum\Models;
9
10
use Illuminate\Database\Eloquent\Model;
11
use Illuminate\Database\Eloquent\SoftDeletes;
12
13
class Note extends Model
14
{
15
    use SoftDeletes;
16
17
    /**
18
     * The database table used by the model.
19
     *
20
     * @var string
21
     */
22
    protected $table = 'notes';
23
24
    /**
25
     * Attributes that should be mass-assignable.
26
     *
27
     * @var array
28
     */
29
    protected $fillable = ['noteable_type', 'noteable_id', 'user_id',
30
        'slug', 'title', 'position', 'closed_at', ];
31
32
    /**
33
     * The attributes excluded from the model's JSON form.
34
     *
35
     * @var array
36
     */
37
    protected $hidden = [];
38
39
    /**
40
     * The attributes that should be casted to native types.
41
     *
42
     * @var array
43
     */
44
    protected $casts = [];
45
46
    /**
47
     * The attributes that should be mutated to dates.
48
     *
49
     * @var array
50
     */
51
    protected $dates = ['deleted_at'];
52
53
    protected static function boot()
54
    {
55
        parent::boot();
56
    }
57
58
    public function noteable()
59
    {
60
        return $this->morphTo('noteable');
61
    }
62
63
    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...
64
    {
65
        return $this->morphMany(\GitScrum\Models\Status::class, 'statusesable')
66
            ->orderby('created_at', 'DESC');
67
    }
68
69
    public function closedUser()
70
    {
71
        return $this->belongsTo(\GitScrum\Models\User::class, 'closed_user_id', 'id');
72
    }
73
74
    public function getConfigStatusIdAttribute()
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...
75
    {
76
        return ConfigStatus::where('type', '=', 'note')
77
            ->where('default', '=', 1)->first()->id;
78
    }
79
80
    public function setClosedUserIdAttribute($value)
81
    {
82
        $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...
83
    }
84
85
    public function setClosedAtAttribute($value)
86
    {
87
        $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...
88
    }
89
}
90