Passed
Pull Request — master (#1830)
by Nico
30:56
created

AbstractSystemData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 32
ccs 4
cts 14
cp 0.2857
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setShip() 0 3 1
A getTalStatusBar() 0 7 1
A __construct() 0 2 1
A update() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Ship\System\Data;
6
7
use Stu\Component\Ship\System\ShipSystemTypeEnum;
8
use Stu\Module\Tal\TalStatusBar;
9
use Stu\Module\Tal\TalStatusBarInterface;
10
use Stu\Orm\Entity\ShipInterface;
11
use Stu\Orm\Repository\ShipSystemRepositoryInterface;
12
13
abstract class AbstractSystemData
14
{
15
    protected ShipInterface $ship;
16
17 5
    public function __construct(private ShipSystemRepositoryInterface $shipSystemRepository)
18
    {
19 5
    }
20
21 3
    public function setShip(ShipInterface $ship): void
22
    {
23 3
        $this->ship = $ship;
24
    }
25
26
    abstract public function getSystemType(): ShipSystemTypeEnum;
27
28
    /**
29
     * updates the system metadata for this specific ship system
30
     */
31
    public function update(): void
32
    {
33
        $system = $this->ship->getShipSystem($this->getSystemType());
34
        $system->setData(json_encode($this, JSON_THROW_ON_ERROR));
35
        $this->shipSystemRepository->save($system);
36
    }
37
38
    protected function getTalStatusBar(string $label, int $value, int $maxValue, string $color): TalStatusBarInterface
39
    {
40
        return (new TalStatusBar())
41
            ->setColor($color)
42
            ->setLabel($label)
43
            ->setMaxValue($maxValue)
44
            ->setValue($value);
45
    }
46
}
47