Passed
Pull Request — master (#1695)
by Nico
40:23 queued 15:53
created

BuildmenuProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 28
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setTemplateVariables() 0 17 2
1
<?php
2
3
namespace Stu\Module\Colony\Lib\Gui\Component;
4
5
use Stu\Component\Building\BuildMenuEnum;
6
use Stu\Lib\Colony\PlanetFieldHostInterface;
7
use Stu\Module\Control\GameControllerInterface;
8
use Stu\Orm\Entity\ColonyInterface;
9
use Stu\Orm\Repository\BuildingRepositoryInterface;
10
11
final class BuildmenuProvider implements GuiComponentProviderInterface
12
{
13
    private BuildingRepositoryInterface $buildingRepository;
14
15
    public function __construct(
16
        BuildingRepositoryInterface $buildingRepository,
17
    ) {
18
        $this->buildingRepository = $buildingRepository;
19
    }
20
21
    /** @param ColonyInterface&PlanetFieldHostInterface $host */
22
    public function setTemplateVariables(
23
        PlanetFieldHostInterface $host,
24
        GameControllerInterface $game
25
    ): void {
26
27
        foreach (BuildMenuEnum::BUILDMENU_IDS as $id) {
28
            $menus[$id]['buildings'] = $this->buildingRepository->getByColonyAndUserAndBuildMenu(
29
                $host,
30
                $game->getUser()->getId(),
31
                $id,
32
                0
33
            );
34
35
            $menus[$id]['name'] = BuildMenuEnum::getDescription($id);
36
        }
37
38
        $game->setTemplateVar('BUILD_MENUS', $menus);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $menus seems to be defined by a foreach iteration on line 27. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
39
    }
40
}
41