TerraformCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 2
cbo 5
dl 0
loc 46
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A configure() 0 6 1
A execute() 0 16 3
1
<?php
2
3
namespace Vehsamrak\Terraformator\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Vehsamrak\Terraformator\Entity\Map;
9
use Vehsamrak\Terraformator\Entity\PreviousLocationMap;
10
use Vehsamrak\Terraformator\LocationGenerator\LocationGenerator;
11
use Vehsamrak\Terraformator\Service\MapTransformer;
12
13
/**
14
 * @author Vehsamrak
15
 */
16
class TerraformCommand extends Command
17
{
18
    private const MAP_WIDTH = 60;
19
    private const MAP_HEIGHT = 30;
20
21
    /** @var LocationGenerator $locationGenerator */
22
    private $locationGenerator;
23
    /** @var MapTransformer $mapTransformer */
24
    private $mapTransformer;
25
26
    /** {@inheritDoc} */
27 2
    public function __construct(
28
        LocationGenerator $locationGenerator,
29
        MapTransformer $mapTransformer
30
    ) {
31 2
        $this->mapTransformer = $mapTransformer;
32 2
        $this->locationGenerator = $locationGenerator;
33 2
        parent::__construct();
34 2
    }
35
36
    /** {@inheritDoc} */
37 2
    protected function configure()
38
    {
39 2
        $this->setName('create');
40 2
        $this->setDescription('Create new map');
41 2
        $this->setHelp('This command allows you to create game map.');
42 2
    }
43
44
    /** {@inheritDoc} */
45 2
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47 2
        $map = new Map();
48
49 2
        for ($y = 1; $y <= self::MAP_HEIGHT; $y++) {
50 2
            for ($x = 1; $x <= self::MAP_WIDTH; $x++) {
51 2
                $surroundingMap = $map->getPreviousLocations($x, $y);
52 2
                $location = $this->locationGenerator->generateLocation($surroundingMap, $x, $y);
53 2
                $map->add($location);
54
            }
55
        }
56
57 2
        $stringMap = $this->mapTransformer->transformToString($map, self::MAP_WIDTH);
58
59 2
        $output->writeln($stringMap);
60 2
    }
61
}
62