Completed
Push — master ( 1ef690...5e5bda )
by Phecho
03:54
created

Comment::target()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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: comments
15
#
16
#  id            :integer          not null, primary key
17
#  message       :text
18
#  target_type   :string(255)
19
#  author_id     :integer
20
#  created_at    :timestamp
21
#  updated_at    :timestamp
22
#  project_id    :integer
23
#  attachment    :string(255)
24
#  line_code     :string(255)
25
#  commit_id     :string(255)
26
#  target_id     :integer
27
#  system        :boolean          default(FALSE), not null
28
#  st_diff       :text
29
#  updated_by_id :integer
30
#  is_award      :boolean
31
#
32
33
namespace Gitamin\Models;
34
35
use AltThree\Validator\ValidatingTrait;
36
use Gitamin\Presenters\CommentPresenter;
37
use Illuminate\Database\Eloquent\Model;
38
use Illuminate\Database\Eloquent\SoftDeletes;
39
use McCool\LaravelAutoPresenter\HasPresenter;
40
41
class Comment extends Model implements HasPresenter
42
{
43
    use SoftDeletes, ValidatingTrait;
44
45
    /**
46
     * The attributes that should be casted to native types.
47
     *
48
     * @var string[]
49
     */
50
    protected $casts = [
51
        'id' => 'int',
52
        'deleted_at' => 'date',
53
    ];
54
55
    /**
56
     * The fillable properties.
57
     *
58
     * @var string[]
59
     */
60
    protected $fillable = [
61
        'message',
62
        'target_type',
63
        'target_id',
64
        'author_id',
65
        'project_id',
66
        'created_at',
67
        'updated_at',
68
    ];
69
70
    /**
71
     * The validation rules.
72
     *
73
     * @var string[]
74
     */
75
    public $rules = [
76
        'author_id' => 'int',
77
        'project_id' => 'int',
78
        'message' => 'required',
79
        'target_type' => 'string|required',
80
        'target_id' => 'int',
81
    ];
82
83
    /**
84
     * A comment belongs to a project.
85
     *
86
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
87
     */
88
    public function project()
89
    {
90
        return $this->belongsTo(Project::class, 'project_id', 'id');
91
    }
92
93
    /**
94
     * Moments can belong to a target.
95
     *
96
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
97
     */
98
    public function target()
99
    {
100
        return $this->belongsTo('Gitamin\\Models\\'.$this->target_type, 'target_id', 'id');
0 ignored issues
show
Documentation introduced by
The property target_type does not exist on object<Gitamin\Models\Comment>. 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...
101
    }
102
103
    /**
104
     * Get the presenter class.
105
     *
106
     * @return string
107
     */
108
    public function getPresenterClass()
109
    {
110
        return CommentPresenter::class;
111
    }
112
}
113