Passed
Push — dev ( eeafb8...d52139 )
by Janko
10:24
created

RepairTaskJobs   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 5%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 58
ccs 2
cts 40
cp 0.05
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A work() 0 49 4
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\Component\Spacecraft\Repair\RepairUtilInterface;
9
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum;
10
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
11
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...
12
use Stu\Orm\Repository\RepairTaskRepositoryInterface;
13
use Stu\Orm\Repository\SpacecraftRepositoryInterface;
14
15
final class RepairTaskJobs implements ProcessTickHandlerInterface
16
{
17 1
    public function __construct(
18
        private RepairTaskRepositoryInterface $repairTaskRepository,
19
        private SpacecraftRepositoryInterface $spacecraftRepository,
20
        private RepairUtilInterface $repairUtil,
21
        private PrivateMessageSenderInterface $privateMessageSender
22 1
    ) {}
23
24
    #[Override]
25
    public function work(): void
26
    {
27
        $result = $this->repairTaskRepository->getFinishedRepairTasks();
28
        foreach ($result as $repairTask) {
29
            $spacecraft = $repairTask->getSpacecraft();
30
31
            if (!$spacecraft->hasEnoughCrew()) {
32
                $this->privateMessageSender->send(
33
                    UserEnum::USER_NOONE,
34
                    $spacecraft->getUser()->getId(),
35
                    sprintf(
36
                        _('Ungenügend Crew auf der %s vorhanden, daher wurde die Reparatur des Systems %s abgebrochen'),
37
                        $spacecraft->getName(),
38
                        $repairTask->getSystemType()->getDescription()
39
                    ),
40
                    PrivateMessageFolderTypeEnum::SPECIAL_SHIP,
41
                    $spacecraft->getHref()
42
                );
43
44
                $this->repairTaskRepository->delete($repairTask);
45
46
                continue;
47
            }
48
49
            $isSuccess = $this->repairUtil->selfRepair($spacecraft, $repairTask);
50
            $this->spacecraftRepository->save($spacecraft);
51
52
            if ($isSuccess) {
53
                $msg = sprintf(
54
                    _('Die Crew der %s hat das System %s auf %d %% reparieren können'),
55
                    $spacecraft->getName(),
56
                    $repairTask->getSystemType()->getDescription(),
57
                    $repairTask->getHealingPercentage()
58
                );
59
            } else {
60
                $msg = sprintf(
61
                    _('Der Reparaturversuch des Systems %s an Bord der %s brachte keine Besserung'),
62
                    $repairTask->getSystemType()->getDescription(),
63
                    $spacecraft->getName()
64
                );
65
            }
66
67
            $this->privateMessageSender->send(
68
                UserEnum::USER_NOONE,
69
                $spacecraft->getUser()->getId(),
70
                $msg,
71
                PrivateMessageFolderTypeEnum::SPECIAL_SHIP,
72
                $spacecraft->getHref()
73
            );
74
        }
75
    }
76
}
77