Passed
Pull Request — develop (#172)
by
unknown
03:18 queued 01:42
created

ReadSettings   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 72
rs 10
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 3 1
A findAll() 0 3 1
A save() 0 3 1
A findByLocale() 0 9 2
A findOneByUuid() 0 10 2
A __construct() 0 3 1
A findDefaultSettings() 0 9 2
A findByCurrency() 0 9 2
A settingsExists() 0 3 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\Model\VO\Currency;
19
use Company\Domain\Model\VO\Locale;
20
use Company\Domain\Storage\Settings\ReadSettings as ReadSettingsDomain;
21
use Company\Domain\Storage\Settings\SettingsEntity;
22
use Company\Infrastructure\Doctrine\Repository\SettingsRepository;
23
use Core\Domain\Common\Model\VO\ResourceUuidInterface;
24
25
class ReadSettings implements ReadSettingsDomain
26
{
27
    private SettingsRepository $settingsRepository;
28
29
    public function __construct(SettingsRepository $settingsRepository)
30
    {
31
        $this->settingsRepository = $settingsRepository;
32
    }
33
34
    public function findAll(): array
35
    {
36
        return $this->settingsRepository->findAll();
37
    }
38
39
    public function findOneByUuid(ResourceUuidInterface $uuid): Settings
40
    {
41
        /** @var SettingsEntity $settingsEntity */
42
        $settingsEntity = $this->settingsRepository->findOneByUuid($uuid);
43
44
        if (!$settingsEntity instanceof SettingsEntity) {
0 ignored issues
show
introduced by
$settingsEntity is always a sub-type of Company\Domain\Storage\Settings\SettingsEntity.
Loading history...
45
            throw new SettingsNotFoundException();
46
        }
47
48
        return $settingsEntity->toModel();
49
    }
50
51
    public function findByLocale(Locale $locale): Settings
52
    {
53
        $settingsEntity = $this->settingsRepository->findByLocale($locale);
54
55
        if (!$settingsEntity instanceof SettingsEntity) {
56
            throw new SettingsNotFoundException();
57
        }
58
59
        return $settingsEntity->toModel();
60
    }
61
62
    public function save(SettingsEntity $settings): void
63
    {
64
        $this->settingsRepository->save($settings);
65
    }
66
67
    public function remove(SettingsEntity $settings): void
68
    {
69
        $this->settingsRepository->remove($settings);
70
    }
71
72
    public function findByCurrency(Currency $currency): Settings
73
    {
74
        $settingsEntity = $this->settingsRepository->findByCurrency($currency);
75
76
        if (!$settingsEntity instanceof SettingsEntity) {
77
            throw new SettingsNotFoundException();
78
        }
79
80
        return $settingsEntity->toModel();
81
    }
82
83
    public function settingsExists(): bool
84
    {
85
        return $this->settingsRepository->settingsExists();
86
    }
87
88
    public function findDefaultSettings(): Settings
89
    {
90
        $settingsEntity = $this->settingsRepository->findOne();
91
92
        if (!$settingsEntity instanceof SettingsEntity) {
93
            throw new SettingsNotFoundException();
94
        }
95
96
        return $settingsEntity->toModel();
97
    }
98
}
99