Passed
Push — dev ( 2c953a...19f0dc )
by Janko
28:50 queued 20:04
created

NextTutorial::handle()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 7
Bugs 2 Features 0
Metric Value
cc 6
eloc 12
c 7
b 2
f 0
nc 6
nop 1
dl 0
loc 16
ccs 0
cts 13
cp 0
crap 42
rs 9.2222
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 (!$user->hasColony()) {
30
            throw new AccessViolation();
31
        } elseif ($user->getState() === UserEnum::USER_STATE_TUTORIAL1) {
32
            $user->setState(UserEnum::USER_STATE_TUTORIAL2);
33
        } elseif ($user->getState() === UserEnum::USER_STATE_TUTORIAL2) {
34
            $user->setState(UserEnum::USER_STATE_TUTORIAL3);
35
        } elseif ($user->getState() === UserEnum::USER_STATE_TUTORIAL3) {
36
            $user->setState(UserEnum::USER_STATE_TUTORIAL4);
37
        } elseif ($user->getState() === UserEnum::USER_STATE_TUTORIAL4) {
38
            $user->setState(UserEnum::USER_STATE_ACTIVE);
39
        }
40
        $this->userRepository->save($user);
41
    }
42
43
44
    public function performSessionCheck(): bool
45
    {
46
        return false;
47
    }
48
}
49