Passed
Push — dev ( 262e9d...837c0e )
by Nico
30:19
created

FinishShipRetrofitJobs::work()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 4
nop 0
dl 0
loc 30
ccs 0
cts 20
cp 0
crap 20
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Tick\Process;
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\Module\Message\Lib\PrivateMessageFolderTypeEnum;
9
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
10
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum 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...
11
use Stu\Module\Ship\Lib\ShipRetrofitInterface;
12
use Stu\Orm\Repository\ColonyShipQueueRepositoryInterface;
13
14
final class FinishShipRetrofitJobs implements ProcessTickHandlerInterface
15
{
16
    public function __construct(private ShipRetrofitInterface $shipRetrofit, private ColonyShipQueueRepositoryInterface $colonyShipQueueRepository, private PrivateMessageSenderInterface $privateMessageSender) {}
17
18
    #[Override]
19
    public function work(): void
20
    {
21
        $queue = $this->colonyShipQueueRepository->getFinishedJobs();
22
        foreach ($queue as $obj) {
23
            if ($obj->getMode() == 2) {
24
25
                $colony = $obj->getColony();
26
27
                $newbuildplan = $obj->getShipBuildplan();
28
                $ship = $obj->getShip();
29
30
                if ($ship == null) {
31
                    return;
32
                }
33
34
                $this->shipRetrofit->updateBy(
35
                    $ship,
36
                    $newbuildplan
37
                );
38
                $this->colonyShipQueueRepository->delete($obj);
39
40
41
                $txt = _("Auf der Kolonie " . $colony->getName() . " wurde die " . $ship->getName() . " umgerüstet");
42
43
                $this->privateMessageSender->send(
44
                    UserEnum::USER_NOONE,
45
                    $colony->getUserId(),
46
                    $txt,
47
                    PrivateMessageFolderTypeEnum::SPECIAL_COLONY
48
                );
49
            }
50
        }
51
    }
52
}