Passed
Push — master ( 0692f7...99bddd )
by Petr
09:18
created

TerraformCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
crap 1
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\LocationGenerator\LocationGenerator;
10
use Vehsamrak\Terraformator\Service\MapTransformer;
11
12
/**
13
 * @author Vehsamrak
14
 */
15
class TerraformCommand extends Command
16
{
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
        $name = null,
29
        LocationGenerator $locationGenerator = null,
30
        MapTransformer $mapTransformer = null
31
    ) {
32 2
        $this->mapTransformer = $mapTransformer ?? new MapTransformer();
33 2
        $this->locationGenerator = $locationGenerator ?? new LocationGenerator();
34 2
        parent::__construct($name = null);
35 2
    }
36
37
    /** {@inheritDoc} */
38 2
    protected function configure()
39
    {
40 2
        $this->setName('create');
41 2
        $this->setDescription('Create new map');
42 2
        $this->setHelp('This command allows you to create game map.');;
43 2
    }
44
45
    /** {@inheritDoc} */
46 2
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48 2
        $map = new Map();
49
50 2
        for ($y = 1; $y <= self::MAP_HEIGHT; $y++) {
51 2
            for ($x = 1; $x <= self::MAP_WIDTH; $x++) {
52 2
                $location = $this->locationGenerator->generateLocation($map, $x, $y);
53 2
                $map->add($location);
54
            }
55
        }
56
57 2
        unset($x, $y);
58
59 2
        $stringMap = $this->mapTransformer->convertToString($map, self::MAP_WIDTH);
60
61 2
        $output->writeln($stringMap);
62 2
    }
63
}
64