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

MessageFolderComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 37
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setTemplateVariables() 0 30 4
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\Message\Lib\PrivateMessageFolderTypeEnum;
11
use Stu\Module\Message\Lib\PrivateMessageUiFactoryInterface;
12
use Stu\Orm\Entity\PrivateMessageFolderInterface;
13
use Stu\Orm\Repository\PrivateMessageFolderRepositoryInterface;
14
15
/**
16
 * Renders the pm folders in the header
17
 */
18
final class MessageFolderComponent implements ComponentInterface
19
{
20 3
    public function __construct(
21
        private PrivateMessageFolderRepositoryInterface $privateMessageFolderRepository,
22
        private PrivateMessageUiFactoryInterface $commUiFactory
23 3
    ) {}
24
25 5
    #[Override]
26
    public function setTemplateVariables(GameControllerInterface $game): void
27
    {
28 5
        $user = $game->getUser();
29
30 5
        $pmFolder = [
31 5
            PrivateMessageFolderTypeEnum::SPECIAL_MAIN,
32 5
            PrivateMessageFolderTypeEnum::SPECIAL_SHIP,
33 5
            PrivateMessageFolderTypeEnum::SPECIAL_STATION,
34 5
            PrivateMessageFolderTypeEnum::SPECIAL_COLONY,
35 5
            PrivateMessageFolderTypeEnum::SPECIAL_TRADE,
36 5
            PrivateMessageFolderTypeEnum::SPECIAL_SYSTEM
37 5
        ];
38 5
        $folder = [];
39
40 5
        foreach ($pmFolder as $folderType) {
41
            if (
42 5
                $folderType === PrivateMessageFolderTypeEnum::SPECIAL_STATION
43 5
                && !$user->hasStationsNavigation()
44
            ) {
45 4
                continue;
46
            }
47
48
            /** @var PrivateMessageFolderInterface $specialFolder */
49 5
            $specialFolder = $this->privateMessageFolderRepository->getByUserAndSpecial($user->getId(), $folderType);
50
51 5
            $folder[$folderType->value] = $this->commUiFactory->createPrivateMessageFolderItem($specialFolder);
52
        }
53
54 5
        $game->setTemplateVar('PM', $folder);
55
    }
56
}
57