Passed
Push — dev ( 94f08a...8536c8 )
by Nico
21:07 queued 14:06
created

NextTutorial::handle()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 25
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 5
Bugs 1 Features 0
Metric Value
cc 5
eloc 10
c 5
b 1
f 0
nc 16
nop 1
dl 0
loc 25
ccs 0
cts 11
cp 0
crap 30
rs 9.6111
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
        }
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