Passed
Pull Request — master (#2331)
by Janko
11:37 queued 06:03
created

RepairTaskJobs   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 12.82%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 56
ccs 5
cts 39
cp 0.1282
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

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