Completed
Push — master ( 63772a...99c307 )
by
unknown
16s
created

GeneralSettingsMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 14 1
A import() 0 15 3
1
<?php
2
3
namespace NerdsAndCompany\Schematic\Mappers;
4
5
use Craft;
6
use NerdsAndCompany\Schematic\Schematic;
7
use NerdsAndCompany\Schematic\Interfaces\MapperInterface;
8
use yii\base\Component as BaseComponent;
9
use craft\models\Info;
10
11
/**
12
 * Schematic General Settings Mapper.
13
 *
14
 * Sync Craft Setups.
15
 *
16
 * @author    Nerds & Company
17
 * @copyright Copyright (c) 2015-2018, Nerds & Company
18
 * @license   MIT
19
 *
20
 * @see      http://www.nerds.company
21
 */
22
class GeneralSettingsMapper extends BaseComponent implements MapperInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function export(array $settings = []): array
28
    {
29 1
        $info = Craft::$app->getInfo();
30
31
        return [
32
            'settings' => [
33 1
                'edition' => $info->edition,
34 1
                'timezone' => $info->timezone,
35 1
                'name' => $info->name,
36 1
                'on' => $info->on,
37 1
                'maintenance' => $info->maintenance,
38
            ],
39
        ];
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function import(array $generalSettings, array $settings = []): array
46
    {
47 1
        if (array_key_exists('settings', $generalSettings)) {
48 1
            Schematic::info('- Saving general settings');
49
50 1
            $record = Craft::$app->getInfo();
51 1
            $record->setAttributes($generalSettings['settings']);
52
53 1
            if (!Craft::$app->saveInfo($record)) {
54 1
                Schematic::warning('- Couldn’t save general settings.');
55
            }
56
        }
57
58 1
        return [];
59
    }
60
}
61