Passed
Push — master ( 8cd431...bc71f5 )
by Janko
09:12
created

SettingsFactory::createSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 71
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 60
CRAP Score 1.0004

Importance

Changes 0
Metric Value
eloc 54
nc 1
nop 3
dl 0
loc 71
c 0
b 0
f 0
cc 1
ccs 60
cts 65
cp 0.9231
crap 1.0004
rs 9.0036

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Stu\Module\Config\Model;
4
5
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Noodlehaus\ConfigInterface;
7
use Stu\Module\Config\StuConfigSettingEnum;
8
9
class SettingsFactory implements SettingsFactoryInterface
10
{
11 2
    public function __construct(private ConfigInterface $config) {}
12
13 4
    #[Override]
14
    public function createSettings(
15
        StuConfigSettingEnum $type,
16
        ?SettingsInterface $parent,
17
        SettingsCacheInterface $settingsCache
18
    ): SettingsInterface {
19
        return match ($type) {
20 4
            StuConfigSettingEnum::ADMIN => new AdminSettings(
21 4
                $parent,
22 4
                $this->createSettingsCore($type, $parent),
23 4
                $settingsCache
24 4
            ),
25 4
            StuConfigSettingEnum::CACHE => new CacheSettings(
26 4
                $parent,
27 4
                $this->createSettingsCore($type, $parent),
28 4
                $settingsCache
29 4
            ),
30 4
            StuConfigSettingEnum::COLONY => new ColonySettings(
31 4
                $parent,
32 4
                $this->createSettingsCore($type, $parent),
33 4
                $settingsCache
34 4
            ),
35 3
            StuConfigSettingEnum::DB => new DbSettings(
36 3
                $parent,
37 3
                $this->createSettingsCore($type, $parent),
38 3
                $settingsCache
39 3
            ),
40 3
            StuConfigSettingEnum::DEBUG => new DebugSettings(
41 3
                $parent,
42 3
                $this->createSettingsCore($type, $parent),
43 3
                $settingsCache
44 3
            ),
45 3
            StuConfigSettingEnum::LOGGING => new LoggingSettings(
46 3
                $parent,
47 3
                $this->createSettingsCore($type, $parent),
48 3
                $settingsCache
49 3
            ),
50 3
            StuConfigSettingEnum::GAME => new GameSettings(
51 3
                $parent,
52 3
                $this->createSettingsCore($type, $parent),
53 3
                $settingsCache
54 3
            ),
55 3
            StuConfigSettingEnum::MAP => new MapSettings(
56 3
                $parent,
57 3
                $this->createSettingsCore($type, $parent),
58 3
                $settingsCache
59 3
            ),
60 2
            StuConfigSettingEnum::RESET => new ResetSettings(
61 2
                $parent,
62 2
                $this->createSettingsCore($type, $parent),
63 2
                $settingsCache
64 2
            ),
65 2
            StuConfigSettingEnum::SQL_LOGGING => new SqlLoggingSettings(
66 2
                $parent,
67 2
                $this->createSettingsCore($type, $parent),
68 2
                $settingsCache
69 2
            ),
70 2
            StuConfigSettingEnum::EMAIL => new EmailSettings(
71 2
                $parent,
72 2
                $this->createSettingsCore($type, $parent),
73 2
                $settingsCache
74 2
            ),
75
            StuConfigSettingEnum::PIRATES => new PirateSettings(
76
                $parent,
77
                $this->createSettingsCore($type, $parent),
78
                $settingsCache
79
            ),
80 4
            StuConfigSettingEnum::SECURITY => new SecuritySettings(
81 4
                $parent,
82 4
                $this->createSettingsCore($type, $parent),
83 4
                $settingsCache
84 4
            )
85
        };
86
    }
87
88 4
    private function createSettingsCore(StuConfigSettingEnum $type, ?SettingsInterface $parent): SettingsCoreInterface
89
    {
90 4
        return new SettingsCore(
91 4
            $parent,
92 4
            $type->getConfigPath(),
93 4
            $this->config
94 4
        );
95
    }
96
}
97