Passed
Push — master ( 91454b...2408fc )
by Nico
22:07 queued 10:43
created

FinishTerraformingJobs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 5%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 31
ccs 1
cts 20
cp 0.05
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A work() 0 27 3
A __construct() 0 1 1
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\Orm\Entity\ColonySandboxInterface;
12
use Stu\Orm\Repository\ColonyTerraformingRepositoryInterface;
13
use Stu\Orm\Repository\PlanetFieldRepositoryInterface;
14
15
final class FinishTerraformingJobs implements ProcessTickHandlerInterface
16
{
17 1
    public function __construct(private ColonyTerraformingRepositoryInterface $colonyTerraformingRepository, private PlanetFieldRepositoryInterface $planetFieldRepository, private PrivateMessageSenderInterface $privateMessageSender) {}
18
19
    #[Override]
20
    public function work(): void
21
    {
22
        $result = $this->colonyTerraformingRepository->getFinishedJobs();
23
        foreach ($result as $colonyTerraforming) {
24
            $colonyField = $colonyTerraforming->getField();
25
26
            $host = $colonyField->getHost();
27
            if ($host instanceof ColonySandboxInterface) {
28
                continue;
29
            }
30
31
            $terraforming = $colonyTerraforming->getTerraforming();
32
            $colonyField->setFieldType($terraforming->getToFieldTypeId());
33
            $colonyField->setTerraforming(null);
34
35
            $this->planetFieldRepository->save($colonyField);
36
37
            $this->colonyTerraformingRepository->delete($colonyTerraforming);
38
            $txt = "Kolonie " . $host->getName() . ": " . $terraforming->getDescription() . " auf Feld " . $colonyField->getFieldId() . " abgeschlossen";
39
40
            $this->privateMessageSender->send(
41
                UserEnum::USER_NOONE,
42
                $host->getUserId(),
43
                $txt,
44
                PrivateMessageFolderTypeEnum::SPECIAL_COLONY,
45
                $host
46
            );
47
        }
48
    }
49
}
50