Passed
Push — develop ( e6f4d5...d3a65c )
by Brent
06:41
created

GenerateCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Command;
4
5
use AsyncInterop\Loop;
6
use Brendt\Stitcher\Stitcher;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class GenerateCommand extends Command
12
{
13
14
    const ROUTE = 'route';
15
16
    /**
17
     * @var Stitcher
18
     */
19
    private $stitcher;
20
21
    public function __construct(string $configPath = './config.yml', array $defaultConfig = []) {
22
        parent::__construct();
23
24
        $this->stitcher = Stitcher::create($configPath, $defaultConfig);
25
    }
26
27
    protected function configure() {
28
        $this->setName('site:generate')
29
            ->setDescription('Generate the website')
30
            ->setHelp("This command generates the website based on the data in the src/ folder.")
31
            ->addArgument(self::ROUTE, null, 'Specify a route to render');
32
    }
33
34
    /**
35
     * @param InputInterface  $input
36
     * @param OutputInterface $output
37
     *
38
     * @return void
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output) {
41
        $route = $input->getArgument(self::ROUTE);
42
        $blanket = $this->stitcher->stitch($route);
43
        $this->stitcher->save($blanket);
44
45
        $publicDir = Stitcher::getParameter('directories.public');
46
47
        if ($route) {
48
            $output->writeln("<fg=green>{$route}</> successfully generated in <fg=green>{$publicDir}</>.");
49
        } else {
50
            $output->writeln("Site successfully generated in <fg=green>{$publicDir}</>.");
51
        }
52
    }
53
54
}
55