Passed
Push — master ( 92a2e9...9d73f4 )
by Nico
41:55
created

CancelMining::cancelMining()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 5
nop 2
dl 0
loc 18
ccs 0
cts 10
cp 0
crap 20
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Ship\Mining;
6
7
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...
8
use Stu\Component\Ship\ShipStateEnum;
9
use Stu\Component\Ship\System\ShipSystemTypeEnum;
10
use Stu\Orm\Entity\ShipInterface;
11
use Stu\Orm\Repository\MiningQueueRepositoryInterface;
12
use Stu\Orm\Repository\ShipRepositoryInterface;
13
use Stu\Module\Ship\Lib\ShipWrapperInterface;
14
15
16
17
final class CancelMining implements CancelMiningInterface
18
{
19
20 4
    public function __construct(
21
        private ShipRepositoryInterface $shipRepository,
22
        private MiningQueueRepositoryInterface $miningQueueRepository,
23 4
    ) {}
24
25
    #[Override]
26
    public function cancelMining(ShipInterface $ship, ShipWrapperInterface $wrapper): bool
27
    {
28
29
30
        $state = $ship->getState();
31
        if ($state === ShipStateEnum::SHIP_STATE_GATHER_RESOURCES) {
32
            if ($ship->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_BUSSARD_COLLECTOR)) {
33
                $wrapper->getShipSystemManager()->deactivate($wrapper, ShipSystemTypeEnum::SYSTEM_BUSSARD_COLLECTOR, true);
34
            }
35
36
            $miningQueue = $this->miningQueueRepository->getByShip($ship->getId());
37
            if ($miningQueue !== null) {
38
                $this->miningQueueRepository->truncateByShipId($ship->getId());
39
            }
40
            $this->setStateNoneAndSave($ship);
41
        }
42
        return false;
43
    }
44
45
    private function setStateNoneAndSave(ShipInterface $ship): void
46
    {
47
        $ship->setState(ShipStateEnum::SHIP_STATE_NONE);
48
        $this->shipRepository->save($ship);
49
    }
50
}
51