Completed
Push — master ( 830e9e...1d6fcc )
by Arjay
08:17
created

HasAddress::getAddressAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Yajra\Address;
4
5
use Yajra\Address\Entities\Barangay;
6
use Yajra\Address\Entities\City;
7
use Yajra\Address\Entities\Province;
8
use Yajra\Address\Entities\Region;
9
10
/**
11
 * @property string   street
12
 * @property Region   region
13
 * @property Province province
14
 * @property City     city
15
 * @property Barangay barangay
16
 */
17
trait HasAddress
18
{
19
    /**
20
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
21
     */
22
    public function region()
23
    {
24
        return $this->belongsTo(Region::class, 'region_id', 'region_id');
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
25
    }
26
27
    /**
28
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
29
     */
30
    public function province()
31
    {
32
        return $this->belongsTo(Province::class, 'province_id', 'province_id');
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
    }
34
35
    /**
36
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
37
     */
38
    public function city()
39
    {
40
        return $this->belongsTo(City::class, 'city_id', 'city_id');
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
41
    }
42
43
    /**
44
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
45
     */
46
    public function barangay()
47
    {
48
        return $this->belongsTo(Barangay::class, 'barangay_id', 'code');
0 ignored issues
show
Bug introduced by
It seems like belongsTo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getAddressAttribute()
55
    {
56
        return sprintf("%s %s, %s, %s",
57
            $this->street,
58
            $this->barangay->description,
59
            $this->city->description,
60
            $this->province->description
61
        );
62
    }
63
}
64