Completed
Push — master ( ff022d...6193b5 )
by Joao
02:18
created

InstallCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 9.5797
c 0
b 0
f 0
cc 1
eloc 43
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace ByJG\Daemon\Console;
4
5
use ByJG\Daemon\Daemonize;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class InstallCommand extends Command
13
{
14
    protected function configure()
15
    {
16
        $this
17
            ->setName('install')
18
            ->setDescription('Install a PHP Class as Linux Daemon')
19
            ->addOption(
20
                'template',
21
                't',
22
                InputOption::VALUE_REQUIRED,
23
                'Defines the default service template -- initd or upstart',
24
                'initd'
25
            )
26
            ->addOption(
27
                'no-check',
28
                'nc',
29
                InputOption::VALUE_NONE,
30
                'No check for path or file errors. Just install. ',
31
                true
32
            )
33
            ->addArgument(
34
                'servicename',
35
                InputArgument::REQUIRED,
36
                'The unix service name.'
37
            )
38
            ->addArgument(
39
                'classname',
40
                InputArgument::REQUIRED,
41
                'The PHP class and method like ClassName::Method'
42
            )
43
            ->addArgument(
44
                'bootstrap',
45
                InputArgument::OPTIONAL,
46
                'The relative path from root directory for the bootstrap file, like vendor/autoload.php',
47
                'vendor/autoload.php'
48
            )
49
            ->addArgument(
50
                'rootdir',
51
                InputArgument::OPTIONAL,
52
                'The root path where your application is installed',
53
                getcwd() . "/"
54
            )
55
            ->addArgument(
56
                'description',
57
                InputArgument::OPTIONAL,
58
                'is an optional service description',
59
                "Daemon generated by Daemonize"
60
            )
61
            ->addArgument(
62
                'args',
63
                InputArgument::IS_ARRAY,
64
                'is an optional arguments for your class'
65
            );
66
    }
67
68
    protected function execute(InputInterface $input, OutputInterface $output)
69
    {
70
        Daemonize::install(
71
            $input->getArgument('servicename'),
72
            $input->getArgument('classname'),
73
            $input->getArgument('bootstrap'),
74
            $input->getArgument('rootdir'),
75
            $input->getOption('template'),
76
            $input->getArgument('description'),
77
            $input->getArgument('args'),
78
            $input->getOption('no-check')
79
        );
80
    }
81
}
82