UserSetting::setHourlyRateAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use App\Primitives\Money;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
9
class UserSetting extends Model
10
{
11
    use SoftDeletes;
12
    
13
    /* @var array $fillable The fields which are mass assignable in the database */
14
    protected $fillable = ['user_id', 'hourly_rate', 'currency'];
15
16
    /**
17
     * Set the hourly rate attribute
18
     *
19
     * @param string $hourlyRate
20
     */
21
    public function setHourlyRateAttribute($hourlyRate)
22
    {
23
        $money = Money::fromPounds($hourlyRate);
24
        $this->attributes['hourly_rate'] = $money->inPence();
25
    }
26
27
    /**
28
     * Get the hourly rate attribute
29
     *
30
     * @param string $hourlyRate
31
     * @return string
32
     */
33
    public function getHourlyRateAttribute($hourlyRate)
34
    {
35
        $money = Money::fromPence($hourlyRate);
36
        return $money->inPoundsAndPence();
37
    }
38
}
39