Passed
Pull Request — master (#1839)
by Nico
51:47 queued 25:19
created

SettingsCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSettings() 0 14 2
A __construct() 0 3 1
1
<?php
2
3
namespace Stu\Module\Config\Model;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Stu\Module\Config\StuConfigSettingEnum;
8
9
class SettingsCache implements SettingsCacheInterface
10
{
11
    /** @var Collection<int, SettingsInterface> */
12
    private Collection $settings;
13
14 5
    public function __construct(private SettingsFactoryInterface $settingsFactory)
15
    {
16 5
        $this->settings = new ArrayCollection();
17
    }
18
19 5
    public function getSettings(StuConfigSettingEnum $type, ?SettingsInterface $parent): SettingsInterface
20
    {
21 5
        $setting = $this->settings->get($type->value);
22 5
        if ($setting === null) {
23
24 5
            $setting = $this->settingsFactory->createSettings($type, $parent, $this);
25
26 5
            $this->settings->set(
27 5
                $type->value,
28 5
                $setting
29 5
            );
30
        }
31
32 5
        return $setting;
33
    }
34
}
35