Passed
Pull Request — master (#1831)
by Nico
29:00
created

RefactorRunner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 15
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refactor() 0 20 4
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Refactor;
6
7
use RuntimeException;
8
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
9
use Stu\Orm\Repository\ShipRepositoryInterface;
10
11
final class RefactorRunner
12
{
13
    public function __construct(
14
        private ShipRepositoryInterface $shipRepository,
15
        private ShipWrapperFactoryInterface $shipWrapperFactory
16
    ) {
17
    }
18
19
    public function refactor(): void
20
    {
21
        foreach ($this->shipRepository->findAll() as $ship) {
22
23
            $astroStartTurn = $ship->getAstroStartTurn();
24
            if ($astroStartTurn === null) {
25
                continue;
26
            }
27
28
            $astroLab = $this->shipWrapperFactory
29
                ->wrapShip($ship)
30
                ->getAstroLaboratorySystemData();
31
32
            if ($astroLab === null) {
33
                throw new RuntimeException('this should not happen');
34
            }
35
36
            $astroLab
37
                ->setAstroStartTurn($astroStartTurn)
38
                ->update();
39
        }
40
    }
41
}
42