Passed
Push — develop ( e3219b...3a1d34 )
by Laurent
01:38
created

SaveSettings   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 6 2
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Company\Infrastructure\Storage\Settings;
15
16
use Company\Domain\Exception\SettingsNotFoundException;
17
use Company\Domain\Model\Settings;
18
use Company\Domain\Storage\Settings\SaveSettings as SaveSettingsInterface;
19
20
class SaveSettings implements SaveSettingsInterface
21
{
22
    private UpdateSettings $updateSettings;
23
    private CreateSettings $createSettings;
24
25
    public function __construct(
26
        UpdateSettings $updateSettings,
27
        CreateSettings $createSettings
28
    ) {
29
        $this->updateSettings = $updateSettings;
30
        $this->createSettings = $createSettings;
31
    }
32
33
    public function save(Settings $settings): void
34
    {
35
        try {
36
            $this->updateSettings->update($settings);
37
        } catch (SettingsNotFoundException $settingsNotFoundException) {
38
            $this->createSettings->create($settings);
39
        }
40
    }
41
}
42