Passed
Push — master ( ccb61d...957889 )
by Karel
17:42
created

SiteRepository::updateOrCreateFromRequest()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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