Passed
Push — dev ( 80c162...225d4f )
by Janko
09:12
created

MessageProvider::setTemplateVariables()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3.0032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 2
nop 1
dl 0
loc 20
ccs 13
cts 14
cp 0.9286
crap 3.0032
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Game\Lib\View\Provider\Message;
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 request;
9
use Stu\Component\Game\GameEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\GameEnum 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...
10
use Stu\Lib\Component\ComponentRegistrationInterface;
11
use Stu\Module\Control\GameControllerInterface;
12
use Stu\Module\Game\Component\GameComponentEnum;
13
use Stu\Module\Game\Lib\View\Provider\ViewComponentProviderInterface;
14
use Stu\Module\Message\Lib\PrivateMessageFolderItem;
15
use Stu\Module\Message\Lib\PrivateMessageUiFactoryInterface;
16
use Stu\Orm\Entity\PrivateMessageFolderInterface;
17
use Stu\Orm\Repository\PrivateMessageFolderRepositoryInterface;
18
19
final class MessageProvider implements ViewComponentProviderInterface
20
{
21 1
    public function __construct(
22
        private PrivateMessageFolderRepositoryInterface $privateMessageFolderRepository,
23
        private ComponentRegistrationInterface $componentRegistration,
24
        private ClassicStyleProvider $ClassicStyleProvider,
0 ignored issues
show
Bug introduced by
The type Stu\Module\Game\Lib\View...ge\ClassicStyleProvider 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...
25
        private MessengerStyleProvider $messengerStyleProvider,
26
        private PrivateMessageUiFactoryInterface $privateMessageUiFactory
27 1
    ) {}
28
29 1
    #[Override]
30
    public function setTemplateVariables(GameControllerInterface $game): void
31
    {
32 1
        if (!request::has('pmcat') && $game->getUser()->isInboxMessengerStyle()) {
33
            $this->messengerStyleProvider->setTemplateVariables($game);
34
        } else {
35 1
            $this->ClassicStyleProvider->setTemplateVariables($game);
36
        }
37
38 1
        $game->setTemplateVar(
39 1
            'PM_CATEGORIES',
40 1
            array_map(
41 1
                fn(PrivateMessageFolderInterface $folder): PrivateMessageFolderItem =>
42 1
                $this->privateMessageUiFactory->createPrivateMessageFolderItem($folder),
43 1
                $this->privateMessageFolderRepository->getOrderedByUser($game->getUser())
44 1
            )
45 1
        );
46
47 1
        $this->componentRegistration->addComponentUpdate(GameComponentEnum::PM);
48 1
        $game->addExecuteJS("initTranslations();", GameEnum::JS_EXECUTION_AFTER_RENDER);
49
    }
50
}
51