Passed
Push — dev ( 7b22bc...94f08a )
by Nico
17:32 queued 10:40
created

LastTutorial::handle()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 10
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 21
ccs 0
cts 11
cp 0
crap 56
rs 8.8333
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
        }
37
38
        if ((int) $user->getState() === UserEnum::USER_STATE_TUTORIAL3) {
39
            $user->setState(UserEnum::USER_STATE_TUTORIAL2);
40
        }
41
42
        if ((int) $user->getState() === UserEnum::USER_STATE_TUTORIAL4) {
43
            $user->setState(UserEnum::USER_STATE_TUTORIAL3);
44
        }
45
46
        $this->userRepository->save($user);
47
    }
48
49
50
    public function performSessionCheck(): bool
51
    {
52
        return false;
53
    }
54
}
55