Completed
Push — master ( 1a65d7...018a8e )
by Nil
03:48
created

Employees::latestOrders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace NilPortugues\Tests\App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Employees extends Model
8
{
9
    /**
10
     * @var bool
11
     */
12
    public $timestamps = false;
13
14
    /**
15
     * @var string
16
     */
17
    protected $table = 'employees';
18
19
    /**
20
     * @var string
21
     */
22
    protected $primaryKey = 'id';
23
24
    /**
25
     * @var array
26
     */
27
    protected $appends = ['full_name'];
28
29
    /**
30
     * @var array
31
     */
32
    protected $fillable = [
33
        'company',
34
        'last_name',
35
        'first_name',
36
        'email_address',
37
        'job_title',
38
        'business_phone',
39
        'home_phone',
40
        'mobile_phone',
41
        'fax_number',
42
        'address',
43
        'city',
44
        'state_province',
45
        'zip_postal_code',
46
        'country_region',
47
        'web_page',
48
        'notes',
49
        'attachments',
50
    ];
51
52
    /**
53
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
54
     */
55
    public function latestOrders()
56
    {
57
        return $this->hasMany(Orders::class, 'employee_id')->limit(10);
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getFullNameAttribute()
64
    {
65
        return $this->first_name.' '.$this->last_name;
0 ignored issues
show
Documentation introduced by
The property first_name does not exist on object<NilPortugues\Tests\App\Models\Employees>. 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 last_name does not exist on object<NilPortugues\Tests\App\Models\Employees>. 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...
66
    }
67
}
68