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

NextTutorial::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\NextTutorial;
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 NextTutorial implements ActionControllerInterface
14
{
15
    public const ACTION_IDENTIFIER = 'B_TUTORIAL_NEXT';
16
17
    private UserRepositoryInterface $userRepository;
18
19
    public function __construct(
20
        UserRepositoryInterface $userRepository
21
    ) {
22
        $this->userRepository = $userRepository;
23
    }
24
25
    public function handle(GameControllerInterface $game): void
26
    {
27
        $user = $game->getUser();
28
29
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL1 || (int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL2 || (int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL3 || (int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL4) {
30
            throw new AccessViolation();
31
        }
32
33
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL1) {
34
            $user->setState(UserEnum::USER_STATE_TUTORIAL2);
35
            $this->userRepository->save($user);
36
        }
37
38
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL2) {
39
            $user->setState(UserEnum::USER_STATE_TUTORIAL3);
40
            $this->userRepository->save($user);
41
        }
42
43
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL3) {
44
            $user->setState(UserEnum::USER_STATE_TUTORIAL4);
45
            $this->userRepository->save($user);
46
        }
47
48
        if ((int) $user->getState() !== UserEnum::USER_STATE_TUTORIAL4) {
49
            $user->setState(UserEnum::USER_STATE_ACTIVE);
50
            $this->userRepository->save($user);
51
        }
52
    }
53
54
55
    public function performSessionCheck(): bool
56
    {
57
        return false;
58
    }
59
}
60