Passed
Push — master ( d2fe6b...be3f36 )
by Karel
13:58
created

ModuleRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 29
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A createFromArray() 0 12 2
A getSettings() 0 3 2
1
<?php
2
3
namespace Chuckbe\Chuckcms\Chuck;
4
5
use Chuckbe\Chuckcms\Models\Module;
6
7
class ModuleRepository
8
{
9
    public static function createFromArray($array)
10
    {
11
        // updateOrCreate the module
12
        $find = Module::where('slug', $array['slug'])->first();
13
14
        if($find == null) {
15
            $result = Module::create($array);
16
        } else {
17
            $result = $find->update($array);
18
        }
19
20
        return $result;
21
    }
22
23
    public static function get()
24
    {
25
        return Module::get();
26
    }
27
28
    /**
29
     * Return the settings array of the module
30
     *
31
     * @var Module $module
32
     **/
33
    public function getSettings(Module $module)
34
    {
35
        return array_key_exists('settings', $module->json) ? $module->json['settings'] : [];
0 ignored issues
show
Bug Best Practice introduced by
The property json does not exist on Chuckbe\Chuckcms\Models\Module. Since you implemented __get, consider adding a @property annotation.
Loading history...
36
    }
37
38
}