Passed
Push — dev ( 5a9cf3...b0d117 )
by Nico
07:29
created

LastTutorial::performSessionCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Maindesk\Action\LastTutorial;
6
7
use Stu\Exception\AccessViolation;
8
use Stu\Module\Control\ActionControllerInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\PlayerSetting\Lib\UserEnum;
11
use Stu\Orm\Repository\UserRepositoryInterface;
12
13
final class LastTutorial implements ActionControllerInterface
14
{
15
    public const ACTION_IDENTIFIER = 'B_TUTORIAL_BACK';
16
17
18
    private UserRepositoryInterface $userRepository;
19
20
    public function __construct(
21
        UserRepositoryInterface $userRepository
22
    ) {
23
        $this->userRepository = $userRepository;
24
    }
25
26
    public function handle(GameControllerInterface $game): void
27
    {
28
        $user = $game->getUser();
29
30
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL2 || (int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL3 || (int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL4) {
31
            throw new AccessViolation();
32
        }
33
34
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL2) {
35
            $user->setState(UserEnum::USER_STATE_TUTORIAL1);
36
            $this->userRepository->save($user);
37
        }
38
39
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL3) {
40
            $user->setState(UserEnum::USER_STATE_TUTORIAL2);
41
            $this->userRepository->save($user);
42
        }
43
44
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL4) {
45
            $user->setState(UserEnum::USER_STATE_TUTORIAL3);
46
            $this->userRepository->save($user);
47
        }
48
    }
49
50
51
    public function performSessionCheck(): bool
52
    {
53
        return false;
54
    }
55
}
56