ProjectLocationTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProjectLocationAttribute() 0 6 3
A setProjectLocationAttribute() 0 6 2
1
<?php
2
3
namespace Sfneal\Models\Traits;
4
5
trait ProjectLocationTrait
6
{
7
    /**
8
     * Retrieve a string with the Article's project city, project state.
9
     *
10
     * @return string|null
11
     */
12
    public function getProjectLocationAttribute()
13
    {
14
        if (isset($this->project_city) && isset($this->project_state)) {
15
            return "{$this->project_city}, {$this->project_state}";
16
        } else {
17
            return null;
18
        }
19
    }
20
21
    /**
22
     * Parse project_location attribute into city and state values.
23
     *
24
     * @param  $value
25
     */
26
    public function setProjectLocationAttribute($value)
27
    {
28
        if (isset($value)) {
29
            $city_state = explode(', ', $value);
30
            $this->attributes['project_city'] = $city_state[0];
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
            $this->attributes['project_state'] = $city_state[1];
32
        }
33
    }
34
}
35