Passed
Push — dev ( 20f168...3a8ec2 )
by Nico
15:39
created

EffectsProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTemplateVariables() 0 27 6
A __construct() 0 5 1
1
<?php
2
3
namespace Stu\Module\Colony\Lib\Gui\Component;
4
5
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...
6
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface;
7
use Stu\Module\Commodity\CommodityTypeEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Commodity\CommodityTypeEnum 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\Commodity\Lib\CommodityCacheInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Orm\Entity\ColonyInterface;
11
use Stu\Orm\Repository\ColonyDepositMiningRepositoryInterface;
12
13
final class EffectsProvider implements PlanetFieldHostComponentInterface
14
{
15 1
    public function __construct(
16
        private readonly ColonyDepositMiningRepositoryInterface $colonyDepositMiningRepository,
17
        private readonly ColonyLibFactoryInterface $colonyLibFactory,
18
        private readonly CommodityCacheInterface $commodityCache
19 1
    ) {}
20
21 4
    #[Override]
22
    public function setTemplateVariables(
23
        $entity,
24
        GameControllerInterface $game
25
    ): void {
26 4
        $commodities = $this->commodityCache->getAll(CommodityTypeEnum::COMMODITY_TYPE_EFFECT);
27
28 4
        $depositMinings = $entity instanceof ColonyInterface ? $this->colonyDepositMiningRepository->getCurrentUserDepositMinings($entity) : [];
29 4
        $prod = $this->colonyLibFactory->createColonyCommodityProduction($entity)->getProduction();
30
31 4
        $effects = [];
32 4
        foreach ($commodities as $value) {
33 4
            $commodityId = $value->getId();
34
35
            //skip deposit effects on asteroid
36 4
            if (array_key_exists($commodityId, $depositMinings)) {
37
                continue;
38
            }
39
40 4
            if (!array_key_exists($commodityId, $prod) || $prod[$commodityId]->getProduction() == 0) {
41 4
                continue;
42
            }
43 4
            $effects[$commodityId]['commodity'] = $value;
44 4
            $effects[$commodityId]['production'] = $prod[$commodityId];
45
        }
46
47 4
        $game->setTemplateVar('EFFECTS', $effects);
48
    }
49
}
50