GenerateCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 17
cts 17
cp 1
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Console\Command;
11
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symplify\PHP7_Sculpin\Application\Command\RunCommand;
17
use Symplify\PHP7_Sculpin\Application\SculpinApplication;
18
use Throwable;
19
20
final class GenerateCommand extends Command
21
{
22
    /**
23
     * @var SculpinApplication
24
     */
25
    private $sculpinApplication;
26
27 2
    public function __construct(SculpinApplication $sculpinApplication)
28
    {
29 2
        $this->sculpinApplication = $sculpinApplication;
30
31 2
        parent::__construct();
32 2
    }
33
34 2
    protected function configure()
35
    {
36 2
        $this->setName('generate');
37 2
        $this->setDescription('Generate a site from source.');
38 2
        $this->addOption('server', null, InputOption::VALUE_NONE, 'Start local server to host your generated site.');
39
40 2
        $this->addOption(
41 2
            'source',
42 2
            null,
43 2
            InputOption::VALUE_REQUIRED,
44 2
            'Directory to load page FROM.',
45 2
            getcwd() . DIRECTORY_SEPARATOR . 'source'
46
        );
47 2
        $this->addOption(
48 2
            'output',
49 2
            null,
50 2
            InputOption::VALUE_REQUIRED,
51 2
            'Directory to generate page TO.',
52 2
            getcwd() . DIRECTORY_SEPARATOR . 'output'
53
        );
54 2
    }
55
56 2
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        try {
59 2
            $runCommand = new RunCommand(
60 2
                (bool) $input->getOption('server'),
61 2
                $input->getOption('source'),
62 2
                $input->getOption('output')
63
            );
64
65 2
            $this->sculpinApplication->runCommand($runCommand);
66
67
            $output->writeln('<info>Website was successfully generated.</info>');
68
69
            return 0;
70 2
        } catch (Throwable $throwable) {
71 2
            $output->writeln(
72 2
                sprintf('<error>%s</error>', $throwable->getMessage())
73
            );
74
75 2
            return 1;
76
        }
77
    }
78
}
79