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

BuildmenuProvider::setTemplateVariables()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 6
rs 10
c 1
b 0
f 0
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