Passed
Push — dev ( 8536c8...ab0086 )
by Nico
24:34 queued 18:07
created

NextTutorial::handle()   B

Complexity

Conditions 7
Paths 17

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 6
Bugs 2 Features 0
Metric Value
cc 7
eloc 12
c 6
b 2
f 0
nc 17
nop 1
dl 0
loc 25
ccs 0
cts 13
cp 0
crap 56
rs 8.8333
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_COLONIZATION_SHIP || (int) $user->getState() === UserEnum::USER_STATE_UNCOLONIZED) {
30
            throw new AccessViolation();
31
        }
32
33
        if ((int) $user->getState() === UserEnum::USER_STATE_TUTORIAL1) {
34
            $user->setState(UserEnum::USER_STATE_TUTORIAL2);
35
        }
36
37
        if ((int) $user->getState() === UserEnum::USER_STATE_TUTORIAL2) {
38
            $user->setState(UserEnum::USER_STATE_TUTORIAL3);
39
        }
40
41
        if ((int) $user->getState() === UserEnum::USER_STATE_TUTORIAL3) {
42
            $user->setState(UserEnum::USER_STATE_TUTORIAL4);
43
        }
44
45
        if ((int) $user->getState() === UserEnum::USER_STATE_TUTORIAL4) {
46
            $user->setState(UserEnum::USER_STATE_ACTIVE);
47
        }
48
49
        $this->userRepository->save($user);
50
    }
51
52
53
    public function performSessionCheck(): bool
54
    {
55
        return false;
56
    }
57
}
58