Passed
Pull Request — master (#1914)
by Janko
81:21
created

SettingsFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 1
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Config\Model;
4
5
use Noodlehaus\ConfigInterface;
6
use Stu\Module\Config\StuConfigSettingEnum;
7
8
class SettingsFactory implements SettingsFactoryInterface
9
{
10 4
    public function __construct(private ConfigInterface $config) {}
11 4
    public function createSettings(
12
        StuConfigSettingEnum $type,
13
        ?SettingsInterface $parent,
14
        SettingsCacheInterface $settingsCache
15
    ): SettingsInterface {
16
        return match ($type) {
17 4
            StuConfigSettingEnum::ADMIN => new AdminSettings(
18 4
                $parent,
19 4
                $this->createSettingsCore($type, $parent),
20 4
                $settingsCache
21 4
            ),
22 4
            StuConfigSettingEnum::CACHE => new CacheSettings(
23 4
                $parent,
24 4
                $this->createSettingsCore($type, $parent),
25 4
                $settingsCache
26 4
            ),
27 4
            StuConfigSettingEnum::COLONY => new ColonySettings(
28 4
                $parent,
29 4
                $this->createSettingsCore($type, $parent),
30 4
                $settingsCache
31 4
            ),
32 4
            StuConfigSettingEnum::DB => new DbSettings(
33 4
                $parent,
34 4
                $this->createSettingsCore($type, $parent),
35 4
                $settingsCache
36 4
            ),
37 4
            StuConfigSettingEnum::DEBUG => new DebugSettings(
38 4
                $parent,
39 4
                $this->createSettingsCore($type, $parent),
40 4
                $settingsCache
41 4
            ),
42 4
            StuConfigSettingEnum::GAME => new GameSettings(
43 4
                $parent,
44 4
                $this->createSettingsCore($type, $parent),
45 4
                $settingsCache
46 4
            ),
47 4
            StuConfigSettingEnum::MAP => new MapSettings(
48 4
                $parent,
49 4
                $this->createSettingsCore($type, $parent),
50 4
                $settingsCache
51 4
            ),
52 4
            StuConfigSettingEnum::RESET => new ResetSettings(
53 4
                $parent,
54 4
                $this->createSettingsCore($type, $parent),
55 4
                $settingsCache
56 4
            ),
57 4
            StuConfigSettingEnum::SQL_LOGGING => new SqlLoggingSettings(
58 4
                $parent,
59 4
                $this->createSettingsCore($type, $parent),
60 4
                $settingsCache
61 4
            ),
62 4
            StuConfigSettingEnum::EMAIL => new EmailSettings(
63 4
                $parent,
64 4
                $this->createSettingsCore($type, $parent),
65 4
                $settingsCache
66 4
            )
67
        };
68
    }
69
70 4
    private function createSettingsCore(StuConfigSettingEnum $type, ?SettingsInterface $parent): SettingsCoreInterface
71
    {
72 4
        return new SettingsCore(
73 4
            $parent,
74 4
            $type->getConfigPath(),
75 4
            $this->config
76 4
        );
77
    }
78
}
79