Test Failed
Pull Request — master (#85)
by Keoghan
06:33
created

Setting::updateOrCreate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Setting extends Model
8
{
9
    protected $guarded = [];
10
11
    public static function updateOrCreate($name, $value)
12
    {
13
        $setting = static::where('name', $name)->first();
14
15
        if ($setting) {
16
            return  $setting->update(['value' => $value]);
17
        }
18
19
        return static::create(['name' => $name, 'value' => $value]);
20
    }
21
}
22