Passed
Push — dev ( b6688d...d42601 )
by Janko
11:12
created

ResearchComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 49
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTemplateVariables() 0 40 4
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Game\Component;
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\Lib\Component\ComponentInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\Research\TechlistRetrieverInterface;
11
use Stu\Module\Template\StatusBarColorEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Template\StatusBarColorEnum 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\Module\Template\StatusBarFactoryInterface;
13
use Stu\Orm\Repository\BuildingCommodityRepositoryInterface;
14
use Stu\Orm\Repository\ResearchedRepositoryInterface;
15
16
/**
17
 * Renders the research state view in the header
18
 */
19
final class ResearchComponent implements ComponentInterface
20
{
21 3
    public function __construct(
22
        private ResearchedRepositoryInterface $researchedRepository,
23
        private StatusBarFactoryInterface $statusBarFactory,
24
        private TechlistRetrieverInterface $techlistRetriever,
25
        private BuildingCommodityRepositoryInterface $buildingCommodityRepository
26 3
    ) {}
27
28 5
    #[Override]
29
    public function setTemplateVariables(GameControllerInterface $game): void
30
    {
31 5
        $user = $game->getUser();
32 5
        $researchStatusBar = '';
33 5
        $currentResearch = $this->researchedRepository->getCurrentResearch($user);
34
35 5
        if ($currentResearch !== []) {
36 1
            $research = current($currentResearch)->getResearch();
37 1
            $researchPoints = $research->getPoints();
38
39 1
            $researchStatusBar = $this
40 1
                ->statusBarFactory
41 1
                ->createStatusBar()
42 1
                ->setColor(StatusBarColorEnum::STATUSBAR_BLUE)
43 1
                ->setLabel('Forschung')
44 1
                ->setMaxValue($researchPoints)
45 1
                ->setValue($researchPoints - current($currentResearch)->getActive())
46 1
                ->setSizeModifier(2);
47
48 1
            $game->setTemplateVar(
49 1
                'CURRENT_RESEARCH_PRODUCTION_COMMODITY',
50 1
                max(
51 1
                    0,
52 1
                    $this->buildingCommodityRepository->getProductionByCommodityAndUser(
53 1
                        $research->getCommodityId(),
54 1
                        $user
55 1
                    )
56 1
                )
57 1
            );
58
        }
59
60 5
        $researchList = $this->techlistRetriever->getResearchList($user);
61 5
        $hasResearchList = $researchList !== [];
62 5
        $hasCurrentResearch = $currentResearch !== [];
63
64 5
        $game->setTemplateVar('CURRENT_RESEARCH', current($currentResearch));
65 5
        $game->setTemplateVar('CURRENT_RESEARCH_STATUS', $researchStatusBar);
66 5
        $game->setTemplateVar('WAITING_RESEARCH', count($currentResearch) === 2 ? $currentResearch[1] : null);
67 5
        $game->setTemplateVar('RESEARCH_POSSIBLE', $hasResearchList || $hasCurrentResearch);
68
    }
69
}
70