Passed
Push — master ( 37217b...efdda9 )
by Nico
19:16 queued 09:28
created

RegenerateSystem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A performSessionCheck() 0 3 1
A __construct() 0 6 1
A handle() 0 24 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Admin\Action\Map\RegenerateSystem;
6
7
use request;
8
use RuntimeException;
9
use Stu\Component\StarSystem\StarSystemCreationInterface;
10
use Stu\Module\Admin\View\Map\ShowSystem\ShowSystem;
11
use Stu\Module\Control\ActionControllerInterface;
12
use Stu\Module\Control\GameControllerInterface;
13
use Stu\Orm\Repository\StarSystemRepositoryInterface;
14
15
final class RegenerateSystem implements ActionControllerInterface
16
{
17
    public const ACTION_IDENTIFIER = 'REGENERATE_SYSTEM';
18
19
    private StarSystemRepositoryInterface $starSystemRepository;
20
21
    private StarSystemCreationInterface $starSystemCreation;
22
23
    public function __construct(
24
        StarSystemRepositoryInterface $starSystemRepository,
25
        StarSystemCreationInterface $starSystemCreation
26
    ) {
27
        $this->starSystemRepository = $starSystemRepository;
28
        $this->starSystemCreation = $starSystemCreation;
29
    }
30
31
    public function handle(GameControllerInterface $game): void
32
    {
33
        $game->setView(ShowSystem::VIEW_IDENTIFIER);
34
35
        $systemId = request::getInt('sysid');
36
37
        $starSystem = $this->starSystemRepository->find($systemId);
38
        if ($starSystem === null) {
39
            return;
40
        }
41
42
        $map = $starSystem->getMapField();
43
        if ($map === null) {
44
            return;
45
        }
46
47
        $systemName = current($this->starSystemRepository->getRandomFreeSystemNames(1));
48
        if ($systemName === false) {
49
            throw new RuntimeException('no free system name available');
50
        }
51
52
        $this->starSystemCreation->recreateStarSystem($map, $systemName->getName());
53
54
        $game->addInformation('Das System wurde neu generiert.');
55
    }
56
57
    public function performSessionCheck(): bool
58
    {
59
        return false;
60
    }
61
}
62