Passed
Pull Request — master (#2027)
by Nico
21:19 queued 10:33
created

AbstractSystemData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Spacecraft\System\Data;
6
7
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
8
use Stu\Module\Template\StatusBarFactoryInterface;
9
use Stu\Module\Template\StatusBarInterface;
10
use Stu\Orm\Entity\SpacecraftInterface;
11
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
12
13
abstract class AbstractSystemData
14
{
15
    protected SpacecraftInterface $spacecraft;
16
17 23
    public function __construct(
18
        private SpacecraftSystemRepositoryInterface $shipSystemRepository,
19
        private StatusBarFactoryInterface $statusBarFactory
20 23
    ) {}
21
22 21
    public function setSpacecraft(SpacecraftInterface $spacecraft): void
23
    {
24 21
        $this->spacecraft = $spacecraft;
25
    }
26
27
    abstract public function getSystemType(): SpacecraftSystemTypeEnum;
28
29
    /**
30
     * updates the system metadata for this specific ship system
31
     */
32 1
    public function update(): void
33
    {
34 1
        $system = $this->spacecraft->getSpacecraftSystem($this->getSystemType());
35 1
        $system->setData(json_encode($this, JSON_THROW_ON_ERROR));
36 1
        $this->shipSystemRepository->save($system);
37
    }
38
39 8
    protected function getStatusBar(string $label, int $value, int $maxValue, string $color): StatusBarInterface
40
    {
41 8
        return $this->statusBarFactory
42 8
            ->createStatusBar()
43 8
            ->setColor($color)
44 8
            ->setLabel($label)
45 8
            ->setMaxValue($maxValue)
46 8
            ->setValue($value);
47
    }
48
}
49