Passed
Push — master ( 784be2...c4713a )
by Nico
58:15 queued 29:26
created

RefactorWarpdriveSplitRunner::refactor()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
nc 4
nop 0
dl 0
loc 18
ccs 0
cts 11
cp 0
crap 30
rs 9.6111
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Ship\Refactor;
6
7
use Stu\Component\Ship\System\ShipSystemTypeEnum;
8
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
9
use Stu\Orm\Repository\ShipRepositoryInterface;
10
11
final class RefactorWarpdriveSplitRunner
12
{
13
    private ShipRepositoryInterface $shipRepository;
14
15
    private ShipWrapperFactoryInterface $shipWrapperFactory;
16
17
    public function __construct(
18
        ShipRepositoryInterface $shipRepository,
19
        ShipWrapperFactoryInterface $shipWrapperFactory
20
    ) {
21
        $this->shipRepository = $shipRepository;
22
        $this->shipWrapperFactory = $shipWrapperFactory;
23
    }
24
25
    public function refactor(): void
26
    {
27
        foreach ($this->shipRepository->findAll() as $ship) {
28
            if (!$ship->hasShipSystem(ShipSystemTypeEnum::SYSTEM_WARPCORE)) {
29
                continue;
30
            }
31
32
            $wrapper = $this->shipWrapperFactory->wrapShip($ship);
33
34
            $warpcore = $wrapper->getWarpCoreSystemData();
35
            $warpdrive = $wrapper->getWarpDriveSystemData();
36
37
            if ($warpcore === null || $warpdrive === null) {
38
                continue;
39
            }
40
41
            $warpdrive->setWarpCoreSplit($warpcore->getWarpCoreSplit())
0 ignored issues
show
Deprecated Code introduced by
The function Stu\Component\Ship\Syste...ata::getWarpCoreSplit() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
            $warpdrive->setWarpCoreSplit(/** @scrutinizer ignore-deprecated */ $warpcore->getWarpCoreSplit())
Loading history...
42
                ->update();
43
        }
44
    }
45
}
46