Passed
Push — master ( 9d76b1...633ac6 )
by Nico
23:01
created

ShowContactModeSwitch::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Message\View\ShowContactModeSwitch;
6
7
use Stu\Module\Control\GameControllerInterface;
8
use Stu\Module\Control\ViewControllerInterface;
9
use Stu\Module\Message\Lib\ContactListModeEnum;
10
use Stu\Module\Message\View\ShowContactModeSwitch\ShowContactModeSwitchRequestInterface;
11
use Stu\Orm\Repository\ContactRepositoryInterface;
12
13
final class ShowContactModeSwitch implements ViewControllerInterface
14
{
15
    public const VIEW_IDENTIFIER = 'SHOW_CONTACT_MODESWITCH';
16
17
    private ShowContactModeSwitchRequestInterface $showContactModeSwitchRequest;
18
19
    private ContactRepositoryInterface $contactRepository;
20
21
    public function __construct(
22
        ShowContactModeSwitchRequestInterface $showContactModeSwitchRequest,
23
        ContactRepositoryInterface $contactRepository
24
    ) {
25
        $this->showContactModeSwitchRequest = $showContactModeSwitchRequest;
26
        $this->contactRepository = $contactRepository;
27
    }
28
29
    public function handle(GameControllerInterface $game): void
30
    {
31
        $contact = $this->contactRepository->find($this->showContactModeSwitchRequest->getContactId());
32
33
        if ($contact === null || $contact->getUserId() !== $game->getUser()->getId()) {
34
            return;
35
        }
36
37
        $game->setPageTitle(_('Status'));
38
        $game->setMacroInAjaxWindow('html/user/contactModeSwitch.twig');
39
        $game->setTemplateVar('contact', $contact);
40
        $game->setTemplateVar('CONTACT_LIST_MODES', ContactListModeEnum::cases());
41
    }
42
}
43