Test Failed
Push — master ( a58c94...1bcec0 )
by Brent
03:26
created

GenerateCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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