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

RefactorRunner::refactor()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 20
ccs 0
cts 13
cp 0
crap 20
rs 9.8666
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