Passed
Push — develop ( 0d66a7...37c69c )
by Laurent
05:34 queued 02:39
created

ConfigureSettingsHandler::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 13
rs 10
c 1
b 0
f 0
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 Administration\Domain\Settings\Handler;
15
16
use Administration\Domain\Protocol\Repository\SettingsRepositoryProtocol;
17
use Administration\Domain\Settings\Command\ConfigureSettings;
18
use Administration\Domain\Settings\Model\Settings;
19
use Administration\Domain\Settings\Model\VO\SettingsUuid;
20
use Core\Domain\Protocol\Common\Command\CommandHandlerProtocol;
21
22
class ConfigureSettingsHandler implements CommandHandlerProtocol
23
{
24
    private SettingsRepositoryProtocol $repository;
25
26
    public function __construct(SettingsRepositoryProtocol $repository)
27
    {
28
        $this->repository = $repository;
29
    }
30
31
    public function __invoke(ConfigureSettings $command): void
32
    {
33
        if ($this->repository->settingsExist()) {
34
            throw new \DomainException('The application is already configured');
35
        }
36
37
        $settings = Settings::create(
38
            SettingsUuid::generate(),
39
            $command->locale(),
40
            $command->currency()
41
        );
42
43
        $this->repository->add($settings);
44
    }
45
}
46