Passed
Push — dev ( eeaa0f...91a85a )
by Janko
26:10
created

SparePartGenerationEventStrategy::processEvent()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 20
nc 4
nop 1
dl 0
loc 30
ccs 0
cts 23
cp 0
crap 30
rs 9.2888
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Component\Event\Strategy;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Stu\Component\Building\BuildingEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Building\BuildingEnum 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\Colony\ColonyFunctionManagerInterface;
9
use Stu\Component\Colony\Storage\ColonyStorageManagerInterface;
10
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum;
11
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
12
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...
13
use Stu\Orm\Entity\EventInterface;
14
use Stu\Orm\Repository\ModuleQueueRepositoryInterface;
15
16
class SparePartGenerationEventStrategy implements EventStrategyInterface
17
{
18
    public function __construct(
19
        private ModuleQueueRepositoryInterface $moduleQueueRepository,
20
        private ColonyFunctionManagerInterface $colonyFunctionManager,
21
        private ColonyStorageManagerInterface $colonyStorageManager,
22
        private PrivateMessageSenderInterface $privateMessageSender
23
    ) {
24
    }
25
26
    public function getEntitiesToLock(EventInterface $event): Collection
27
    {
28
        return new ArrayCollection();
29
    }
30
31
    public function processEvent(EventInterface $event): void
32
    {
33
        foreach ($this->moduleQueueRepository->findAll() as $queue) {
34
            $buildingFunction = $queue->getBuildingFunction();
35
36
            if (
37
                $buildingFunction === BuildingEnum::BUILDING_FUNCTION_FABRICATION_HALL ||
38
                $buildingFunction === BuildingEnum::BUILDING_FUNCTION_TECH_CENTER
39
            ) {
40
                $colony = $queue->getColony();
41
42
                if ($this->colonyFunctionManager->hasActiveFunction($colony, $buildingFunction)) {
43
                    $this->colonyStorageManager->upperStorage(
44
                        $colony,
45
                        $queue->getModule()->getCommodity(),
46
                        $queue->getAmount()
47
                    );
48
49
                    $this->privateMessageSender->send(
50
                        UserEnum::USER_NOONE,
51
                        $colony->getUser()->getId(),
52
                        sprintf(
53
                            _('Es wurden %d %s hergestellt'),
54
                            $queue->getAmount(),
55
                            $queue->getModule()->getName()
56
                        ),
57
                        PrivateMessageFolderTypeEnum::SPECIAL_COLONY
58
                    );
59
60
                    $this->moduleQueueRepository->delete($queue);
61
                }
62
            }
63
        }
64
    }
65
}
66