RunCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 16 2
A loadConfig() 0 13 3
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
use Fructify\Reload\Application\ServerApplication;
10
11
class RunCommand extends Command
12
{
13
    protected function configure()
14
    {
15
        $this->setName('server:run')
16
            ->setAliases(array('sr'))
17
            ->setDescription('Starts a live reload server.')
18
            ->addArgument('address', InputArgument::OPTIONAL, 'Address:port', '127.0.0.1:35729')
19
            ->addOption('config', '-c', InputOption::VALUE_OPTIONAL, 'Path to livereload.json')
20
            ->addOption('no-watch', '', InputOption::VALUE_NONE, 'Disable watching')
21
            ;
22
    }
23
24
    protected function execute(InputInterface $input, OutputInterface $output)
25
    {
26
        $noWatching = $input->getOption('no-watch');
27
        $address = $input->getArgument('address', '127.0.0.1:35729');
0 ignored issues
show
Unused Code introduced by
The call to InputInterface::getArgument() has too many arguments starting with '127.0.0.1:35729'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
28
        list($host, $port) = explode(':', $address);
29
        $output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
30
        $output->writeln('Quit the server with CONTROL-C.');
31
        $output->writeln('');
32
        $app = new ServerApplication($host, $port);
33
        if(!$noWatching){
34
            $config = $this->loadConfig($input, $output);
35
            $app->watching($config['period'], $config);
36
        }
37
        $app->setOutput($output);
38
        $app->run();
39
    }
40
41
    protected function loadConfig(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Unused Code introduced by
The parameter $output 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...
42
    {
43
        $configFile = $input->getOption('config');
44
        if($configFile === null){
45
            $configFile = 'livereload.json';
46
        }
47
        if(!file_exists($configFile)){
48
            throw new \Exception("$configFile not found.");
49
        }
50
51
        $config = json_decode(file_get_contents($configFile), true);
52
        return $config;
53
    }
54
}