Completed
Push — master ( 89bfcf...4ab803 )
by Vladimir
02:41
created

WatchCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 31 4
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Command;
9
10
use allejo\stakx\Exception\FileAwareException;
11
use allejo\stakx\Utilities\StrUtils;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class WatchCommand extends BuildableCommand
16
{
17
    protected function configure()
18
    {
19
        parent::configure();
20
21
        $this->setName('watch');
22
        $this->setDescription('Watch the source folder and rebuild the website as files change');
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        parent::execute($input, $output);
28
29
        try
30
        {
31
            $this->configureBuild($input);
32
33
            $output->writeln('<fg=black;bg=yellow>Heads up! You are using an experimental feature.</>');
34
35
            $this->website->watch();
36
        }
37
        catch (FileAwareException $e)
38
        {
39
            $output->writeln(StrUtils::interpolate(
40
                "Your website failed to build with the following error in file '{file}'{line}: {message}", array(
41
                    'file' => $e->getPath(),
42
                    'line' => (($l = $e->getLineNumber()) >= 0) ? ' on line ' . $l : '',
43
                    'message' => $e->getMessage()
44
                )
45
            ));
46
        }
47
        catch (\Exception $e)
48
        {
49
            $output->writeln(sprintf('Your website failed to build with the following error: %s',
50
                $e->getMessage()
51
            ));
52
        }
53
54
        return 1;
55
    }
56
}
57