Issue   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 6
Bugs 1 Features 4
Metric Value
wmc 7
c 6
b 1
f 4
lcom 0
cbo 4
dl 0
loc 117
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A author() 0 4 1
A comments() 0 4 1
A getUrlAttribute() 0 4 1
A scopeVisible() 0 4 1
A project() 0 4 1
A getHumanStatusAttribute() 0 7 1
A getPresenterClass() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
# == Schema Information
13
#
14
# Table name: issues
15
#
16
#  id            :integer          not null, primary key
17
#  title         :string(255)
18
#  assignee_id   :integer
19
#  author_id     :integer
20
#  project_id    :integer
21
#  created_at    :timestamp
22
#  updated_at    :timestamp
23
#  position      :integer          default(0)
24
#  branch_name   :string(255)
25
#  description   :text
26
#  milestone_id  :integer
27
#  state         :string(255)
28
#  iid           :integer
29
#  updated_by_id :integer
30
#
31
32
namespace Gitamin\Models;
33
34
use AltThree\Validator\ValidatingTrait;
35
use Gitamin\Presenters\IssuePresenter;
36
use Illuminate\Database\Eloquent\Model;
37
use Illuminate\Database\Eloquent\SoftDeletes;
38
use McCool\LaravelAutoPresenter\HasPresenter;
39
40
class Issue extends Model implements HasPresenter
41
{
42
    use SoftDeletes, ValidatingTrait;
43
44
    /**
45
     * The accessors to append to the model's serialized form.
46
     *
47
     * @var string[]
48
     */
49
    protected $appends = ['human_status'];
50
51
    /**
52
     * The attributes that should be casted to native types.
53
     *
54
     * @var string[]
55
     */
56
    protected $casts = [
57
        'id' => 'int',
58
        'deleted_at' => 'date',
59
    ];
60
61
    /**
62
     * The fillable properties.
63
     *
64
     * @var string[]
65
     */
66
    protected $fillable = [
67
        'author_id',
68
        'project_id',
69
        'title',
70
        'description',
71
        'created_at',
72
        'updated_at',
73
    ];
74
75
    /**
76
     * The validation rules.
77
     *
78
     * @var string[]
79
     */
80
    public $rules = [
81
        'author_id' => 'int',
82
        'project_id' => 'int',
83
        'title' => 'required',
84
        'description' => 'required',
85
    ];
86
87
    /**
88
     * Finds all visible issues.
89
     *
90
     * @param \Illuminate\Database\Eloquent\Builder $query
91
     *
92
     * @return \Illuminate\Database\Eloquent\Builder
93
     */
94
    public function scopeVisible($query)
95
    {
96
        return $query->where('state', null);
97
    }
98
99
    /**
100
     * An issue belongs to a project.
101
     *
102
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
103
     */
104
    public function project()
105
    {
106
        return $this->belongsTo(Project::class, 'project_id', 'id');
107
    }
108
109
    /**
110
     * An issue belongs to an author.
111
     *
112
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
113
     */
114
    public function author()
115
    {
116
        return $this->belongsTo(User::class, 'author_id', 'id');
117
    }
118
119
    /**
120
     * Returns all comments of the issue.
121
     *
122
     * @return \Gitamin\Models\Comment[]
123
     */
124
    public function comments()
125
    {
126
        return Comment::where('target_type', '=', 'Issue')->where('target_id', '=', $this->id)->orderBy('id', 'asc')->get();
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Gitamin\Models\Issue>. 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...
127
    }
128
129
    /**
130
     * Returns a human readable version of the status.
131
     *
132
     * @return string
133
     */
134
    public function getHumanStatusAttribute()
135
    {
136
        $statuses = trans('gitamin.issues.status');
137
138
        return $statuses[rand(0, 2)];
139
        //return $statuses[$this->state];
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
140
    }
141
142
    public function getUrlAttribute()
143
    {
144
        return route('projects.issue_show', ['owner' => $this->project->owner_path, 'project' => $this->project->path, 'issue' => $this->id]);
0 ignored issues
show
Documentation introduced by
The property project does not exist on object<Gitamin\Models\Issue>. 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 id does not exist on object<Gitamin\Models\Issue>. 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...
145
    }
146
147
    /**
148
     * Get the presenter class.
149
     *
150
     * @return string
151
     */
152
    public function getPresenterClass()
153
    {
154
        return IssuePresenter::class;
155
    }
156
}
157