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

FinishBuildJobs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 4.76%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 29
ccs 1
cts 21
cp 0.0476
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A work() 0 25 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\Component\Building\BuildingManagerInterface;
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\Entity\ColonySandboxInterface;
13
use Stu\Orm\Repository\PlanetFieldRepositoryInterface;
14
15
final class FinishBuildJobs implements ProcessTickHandlerInterface
16
{
17 1
    public function __construct(private PlanetFieldRepositoryInterface $planetFieldRepository, private PrivateMessageSenderInterface $privateMessageSender, private BuildingManagerInterface $buildingManager) {}
18
19
    #[Override]
20
    public function work(): void
21
    {
22
        $result = $this->planetFieldRepository->getByConstructionFinish(time());
23
        foreach ($result as $field) {
24
            $activationDetails = $this->buildingManager->finish($field, $field->getActivateAfterBuild());
25
            $host = $field->getHost();
26
            if ($host instanceof ColonySandboxInterface) {
27
                continue;
28
            }
29
30
            $txt = sprintf(
31
                "Kolonie %s: %s auf Feld %s fertiggestellt\n%s",
32
                $host->getName(),
33
                $field->getBuilding()->getName(),
34
                $field->getFieldId(),
35
                $activationDetails ?? ''
36
            );
37
38
            $this->privateMessageSender->send(
39
                UserEnum::USER_NOONE,
40
                $host->getUserId(),
41
                $txt,
42
                PrivateMessageFolderTypeEnum::SPECIAL_COLONY,
43
                $host
44
            );
45
        }
46
    }
47
}
48