SiteRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 23
c 2
b 1
f 0
dl 0
loc 41
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromArray() 0 6 1
B updateOrCreateFromRequest() 0 31 6
1
<?php
2
3
namespace Chuckbe\Chuckcms\Chuck;
4
5
use Chuckbe\Chuckcms\Models\Site;
6
7
class SiteRepository
8
{
9
    public static function updateOrCreateFromRequest($req)
10
    {
11
        $settings = [];
12
        foreach ($req->get('company') as $cmpKey => $cmpValue) {
13
            $settings['company'][$cmpKey] = $cmpValue;
14
        }
15
        foreach ($req->get('socialmedia') as $smKey => $smValue) {
16
            $settings['socialmedia'][$smKey] = $smValue;
17
        }
18
        foreach ($req->get('favicon') as $faviKey => $faviValue) {
19
            $settings['favicon'][$faviKey] = $faviValue;
20
        }
21
        foreach ($req->get('logo') as $logoKey => $logoValue) {
22
            $settings['logo'][$logoKey] = $logoValue;
23
        }
24
        foreach ($req->get('integrations') as $igsKey => $igsValue) {
25
            $settings['integrations'][$igsKey] = $igsValue;
26
        }
27
        $settings['lang'] = implode(',', $req->get('lang'));
28
        $settings['domain'] = $req->get('site_domain');
29
30
        // updateOrCreate the site
31
        $result = Site::updateOrCreate(
32
            ['id' => $req->get('site_id')],
33
            ['name'        => $req->get('site_name'),
34
                'slug'     => $req->get('site_slug'),
35
                'domain'   => $req->get('site_domain'),
36
                'settings' => $settings, ]
37
        );
38
39
        return $result;
40
    }
41
42
    public static function createFromArray($array)
43
    {
44
        // updateOrCreate the site
45
        $result = Site::create($array);
46
47
        return $result;
48
    }
49
}
50