Passed
Push — dev ( b6688d...d42601 )
by Janko
11:12
created

ComponentRegistration::addComponentUpdate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Component;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
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...
10
11
final class ComponentRegistration implements ComponentRegistrationInterface
12
{
13
    /** @var Collection<string, ComponentUpdate> */
14
    private Collection $componentUpdates;
15
16
    /** @var Collection<string, ComponentEnumInterface> */
17
    private Collection $registeredComponents;
18
19 7
    public function __construct()
20
    {
21 7
        $this->componentUpdates = new ArrayCollection();
22 7
        $this->registeredComponents = new ArrayCollection();
23
    }
24
25 5
    #[Override]
26
    public function addComponentUpdate(ComponentEnumInterface $componentEnum, bool $isInstantUpdate = true): void
27
    {
28 5
        $id = $this->getId($componentEnum);
29 5
        if (!$this->componentUpdates->containsKey($id)) {
30 5
            $this->componentUpdates[$id] = new ComponentUpdate($componentEnum, $isInstantUpdate);
31
        }
32
    }
33
34 5
    #[Override]
35
    public function registerComponent(ComponentEnumInterface $componentEnum): void
36
    {
37 5
        $id = $this->getId($componentEnum);
38 5
        if (!$this->registeredComponents->containsKey($id)) {
39 5
            $this->registeredComponents->set($id, $componentEnum);
40
        }
41
    }
42
43 171
    #[Override]
44
    public function getRegisteredComponents(): Collection
45
    {
46 171
        return $this->registeredComponents;
47
    }
48
49 171
    #[Override]
50
    public function getComponentUpdates(): Collection
51
    {
52 171
        return $this->componentUpdates;
53
    }
54
55 169
    #[Override]
56
    public function resetComponents(): void
57
    {
58 169
        $this->componentUpdates->clear();
59 169
        $this->registeredComponents->clear();
60
    }
61
62 6
    private function getId(ComponentEnumInterface $componentEnum): string
63
    {
64 6
        return strtoupper(sprintf(
65 6
            '%s_%s',
66 6
            $componentEnum->getModuleView()->value,
67 6
            $componentEnum->getValue()
68 6
        ));
69
    }
70
}
71