Passed
Pull Request — master (#209)
by
unknown
10:30
created

Country::languages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Country Entity.
4
 *
5
 * @package App\Entities\Country
6
 *
7
 * @author    Nick Menke <[email protected]>
8
 * @copyright 2018-2020 Nick Menke
9
 *
10
 * @link https://github.com/nlmenke/vertebrae
11
 */
12
13
declare(strict_types=1);
14
15
namespace App\Entities\Country;
16
17
use App\Entities\AbstractEntity;
18
use App\Entities\Currency\Currency;
19
use App\Entities\Language\Language;
20
use App\Entities\Locale\Locale;
21
use Illuminate\Database\Eloquent\Relations\BelongsTo;
22
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
23
use Illuminate\Database\Eloquent\SoftDeletes;
24
25
/**
26
 * The Country entity class.
27
 *
28
 * This class contains any functions required to access and manipulate country
29
 * models.
30
 *
31
 * @since x.x.x introduced
32
 */
33
class Country extends AbstractEntity
34
{
35
    use SoftDeletes;
36
37
    /**
38
     * The attributes that are mass assignable.
39
     *
40
     * @var array
41
     */
42
    protected $fillable = [
43
        'currency_id',
44
        'iso_alpha_2',
45
        'iso_alpha_3',
46
        'iso_numeric',
47
        'name',
48
    ];
49
50
    /**
51
     * The currency relationship instance.
52
     *
53
     * @return BelongsTo
54
     */
55 4
    public function currency(): BelongsTo
56
    {
57 4
        return $this->belongsTo(Currency::class);
58
    }
59
60
    /**
61
     * Get the currency attribute.
62
     *
63
     * @return Currency|null
64
     */
65
    public function getCurrency(): ?Currency
66
    {
67
        return $this->getAttribute('currency');
68
    }
69
70
    /**
71
     * Get the iso_alpha_2 attribute.
72
     *
73
     * @return string
74
     */
75
    public function getIsoAlpha2(): string
76
    {
77
        return $this->getAttribute('iso_alpha_2');
78
    }
79
80
    /**
81
     * Get the iso_alpha_3 attribute.
82
     *
83
     * @return string
84
     */
85
    public function getIsoAlpha3(): string
86
    {
87
        return $this->getAttribute('iso_alpha_3');
88
    }
89
90
    /**
91
     * Get the iso_numeric attribute.
92
     *
93
     * @return string
94
     */
95
    public function getIsoNumeric(): string
96
    {
97
        return $this->getAttribute('iso_numeric');
98
    }
99
100
    /**
101
     * Get the name attribute.
102
     *
103
     * @return string
104
     */
105
    public function getName(): string
106
    {
107
        return $this->getAttribute('name');
108
    }
109
110
    /**
111
     * The languages relationship instance.
112
     *
113
     * @return HasManyThrough
114
     */
115 4
    public function languages(): HasManyThrough
116
    {
117 4
        return $this->hasManyThrough(Language::class, Locale::class, 'country_id', 'id', 'id', 'language_id');
118
    }
119
}
120