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

NextTutorial   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 45
ccs 0
cts 20
cp 0
rs 10
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 26 9
A performSessionCheck() 0 3 1
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