Passed
Pull Request — master (#1685)
by Nico
30:06
created

RefactorWarpdriveSplitRunner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
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