Passed
Push — master ( ea03fa...981937 )
by Nico
23:24 queued 15:02
created

EditPassable::performSessionCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Admin\Action\Map\EditPassable;
6
7
use Stu\Module\Admin\View\Map\Noop\Noop;
8
use Stu\Module\Control\ActionControllerInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Orm\Entity\Map;
11
use Stu\Orm\Repository\MapRegionRepositoryInterface;
12
use Stu\Orm\Repository\MapRepositoryInterface;
13
use Stu\Orm\Repository\MapFieldTypeRepositoryInterface;
14
15
final class EditPassable implements ActionControllerInterface
16
{
17
    public const ACTION_IDENTIFIER = 'B_EDIT_PASSABLE';
18
19
    private EditPassableRequestInterface $editPassableRequest;
20
21
    private MapRegionRepositoryInterface $mapRegionRepository;
22
23
    private MapRepositoryInterface $mapRepository;
24
25
    private MapFieldTypeRepositoryInterface $mapFieldTypeRepository;
26
27
    public function __construct(
28
        EditPassableRequestInterface $editPassableRequest,
29
        MapRegionRepositoryInterface $mapRegionRepository,
30
        MapFieldTypeRepositoryInterface $mapFieldTypeRepository,
31
        MapRepositoryInterface $mapRepository
32
    ) {
33
        $this->editPassableRequest = $editPassableRequest;
34
        $this->mapRegionRepository = $mapRegionRepository;
35
        $this->mapFieldTypeRepository = $mapFieldTypeRepository;
36
        $this->mapRepository = $mapRepository;
37
    }
38
39
    public function handle(GameControllerInterface $game): void
40
    {
41
        $selectedField = $this->mapRepository->find($this->editPassableRequest->getFieldId());
42
43
        if ($selectedField === null) {
44
            return;
45
        }
46
47
        $selectedMapFType = $selectedField->getFieldType();
48
49
        $passable = $this->editPassableRequest->getPassable();
50
51
        if ($passable === 1) {
52
            $selectedMapFType->setPassable(true);
53
        }
54
55
        if ($passable === 2) {
56
            $selectedMapFType->setPassable(false);
57
        }
58
59
        $this->mapFieldTypeRepository->save($selectedMapFType);
60
61
        $game->setView(Noop::VIEW_IDENTIFIER);
62
    }
63
64
    public function performSessionCheck(): bool
65
    {
66
        return false;
67
    }
68
}
69