Passed
Push — dev ( f3fb83...7b22bc )
by Nico
15:54 queued 09:01
created

LastTutorial   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 40
ccs 0
cts 13
cp 0
rs 10
wmc 6

3 Methods

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