Passed
Push — dev ( eeaa0f...91a85a )
by Janko
26:10
created

NpcShipHandling::processUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Tick\Ship\ManagerComponent;
4
5
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
7
use Stu\Module\Tick\User\UserTickComponentInterface;
8
use Stu\Orm\Entity\ShipInterface;
9
use Stu\Orm\Entity\UserInterface;
10
use Stu\Orm\Repository\ShipRepositoryInterface;
11
12
class NpcShipHandling implements ManagerComponentInterface, UserTickComponentInterface
13
{
14
    public function __construct(private ShipRepositoryInterface $shipRepository, private ShipWrapperFactoryInterface $shipWrapperFactory)
15
    {
16
    }
17
18
    /**
19
     * @deprecated
20
     */
21
    #[Override]
22
    public function work(): void
23
    {
24
        foreach ($this->shipRepository->getNpcShipsForTick() as $ship) {
25
            $this->processShip($ship);
26
        }
27
    }
28
29
    #[Override]
30
    public function processUser(UserInterface $user): void
31
    {
32
        foreach ($this->shipRepository->getByUser($user) as $ship) {
33
            $this->processShip($ship);
34
        }
35
    }
36
37
    private function processShip(ShipInterface $ship): void
38
    {
39
        $wrapper = $this->shipWrapperFactory->wrapShip($ship);
40
        $reactor = $wrapper->getReactorWrapper();
41
        if ($reactor === null) {
42
            return;
43
        }
44
45
        $epsSystem = $wrapper->getEpsSystemData();
46
        $warpdrive = $wrapper->getWarpDriveSystemData();
47
48
        //load EPS
49
        if ($epsSystem !== null) {
50
            $epsSystem->setEps($epsSystem->getEps() + $reactor->getEffectiveEpsProduction())->update();
51
        }
52
53
        //load warpdrive
54
        if ($warpdrive !== null) {
55
            $warpdrive->setWarpDrive($warpdrive->getWarpDrive() + $reactor->getEffectiveWarpDriveProduction())->update();
56
        }
57
    }
58
}
59