InitCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
namespace Fructify\Reload\Command;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
11
class InitCommand extends Command
12
{
13
    protected function configure()
14
    {
15
        $this->setName('livereload:init')
16
            ->setAliases(array('init'))
17
            ->setDescription('Initialize livereload.json.')
18
            ->addOption('force', '-f', InputOption::VALUE_NONE, 'force rewrite livereload.json')
19
            ;
20
    }
21
22
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        $forceRewrite = $input->getOption('force');
25
        if(!$forceRewrite && file_exists('livereload.json')){
26
            $output->writeln("<error>livereload.json file exists.\nplease use --force to overwrite.</error>");
27
            return;
28
        }
29
        $this->writeConfig($input, $output);
30
    }
31
32
    protected function writeConfig(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $input is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        $json = <<<EOT
35
{
36
    "period": 1,
37
    "watch": {
38
        "web/css/": "*.css",
39
        "web/js/": "*.js",
40
        "web/img/": "\\\\.png|gif|jpg$"
41
    }
42
}
43
EOT
44
;
45
        file_put_contents('livereload.json', $json);
46
        $output->writeln("<info>livereload.json is generated.</info>");
47
    }
48
}