Passed
Push — dev6 ( 5ebf7f...1a3248 )
by Ron
16:55
created

AppSettingsTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 17
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveSettings() 0 6 1
A saveArray() 0 5 2
1
<?php
2
3
namespace App\Traits;
4
5
use App\Models\AppSettings;
6
7
/**
8
 *  AllowTrait only has one function to check permission for the policies
9
 */
10
trait AppSettingsTrait
11
{
12
    //  Save an individual setting into the database so that it can be modified from the hard coded setting
13
    protected function saveSettings($key, $value)
14
    {
15
        AppSettings::firstOrCreate(
16
            ['key'   => $key],
17
            ['value' => $value]
18
        )->update(['value' => $value]);
19
    }
20
21
    //  Array must be in the form of ['key' => 'value] in order to be properly updated
22
    protected function saveArray($settingArray)
23
    {
24
        foreach($settingArray as $key => $value)
25
        {
26
            $this->saveSettings($key, $value);
27
        }
28
    }
29
}
30