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

LastTutorial   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 41
ccs 0
cts 17
cp 0
rs 10
wmc 9

3 Methods

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