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

NpcShipHandling   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 44
ccs 0
cts 19
cp 0
rs 10
c 1
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A processUser() 0 5 2
A work() 0 5 2
A processShip() 0 19 4
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