Completed
Push — master ( 2ae4f2...39cf12 )
by Tomáš
03:17 queued 16s
created

GenerateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 82.61%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 58
ccs 19
cts 23
cp 0.8261
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A configure() 0 6 1
A execute() 0 21 2
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 string
24
     */
25
    private $sourceDirectory;
26
27
    /**
28
     * @var string
29
     */
30
    private $outputDirectory;
31
32
    /**
33
     * @var SculpinApplication
34
     */
35
    private $sculpinApplication;
36
37 1
    public function __construct(
38
        string $sourceDirectory,
39
        string $outputDirectory,
40
        SculpinApplication $sculpinApplication
41
    ) {
42 1
        $this->sourceDirectory = $sourceDirectory;
43 1
        $this->outputDirectory = $outputDirectory;
44 1
        $this->sculpinApplication = $sculpinApplication;
45
46 1
        parent::__construct();
47 1
    }
48
49 1
    protected function configure()
50
    {
51 1
        $this->setName('generate');
52 1
        $this->setDescription('Generate a site from source.');
53 1
        $this->addOption('server', null, InputOption::VALUE_NONE, 'Start local server to host your generated site.');
54 1
    }
55
56 1
    protected function execute(InputInterface $input, OutputInterface $output)
57
    {
58
        try {
59 1
            $runCommand = new RunCommand(
60 1
                (bool) $input->getOption('server'),
61 1
                $this->sourceDirectory,
62 1
                $this->outputDirectory
63
            );
64 1
            $this->sculpinApplication->runCommand($runCommand);
65
66 1
            $output->writeln('<info>Website was successfully generated.</info>');
67
68 1
            return 0;
69
        } catch (Throwable $throwable) {
70
            $output->writeln(
71
                sprintf('<error>%s</error>', $throwable->getMessage())
72
            );
73
74
            return 1;
75
        }
76
    }
77
}
78