BaseCommand   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 11
lcom 1
cbo 3
dl 0
loc 106
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 7 1
fire() 0 1 ?
A info() 0 4 1
A line() 0 5 2
A comment() 0 4 1
A question() 0 4 1
A error() 0 4 1
A argument() 0 7 2
A option() 0 7 2
1
<?php
2
3
namespace Factory\Console;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
abstract class BaseCommand extends Command
10
{
11
    /**
12
     * @var InputInterface
13
     */
14
    protected $input;
15
    /**
16
     * @var OutputInterface
17
     */
18
    protected $output;
19
20
    protected function execute(InputInterface $input, OutputInterface $output)
21
    {
22
        $this->input = $input;
23
        $this->output = $output;
24
25
        $this->fire();
26
    }
27
28
    abstract public function fire();
29
30
    /**
31
     * Write a string as information output.
32
     *
33
     * @param  string  $string
34
     * @return void
35
     */
36
    public function info($string)
37
    {
38
        $this->line($string, 'info');
39
    }
40
41
    /**
42
     * Write a string as standard output.
43
     *
44
     * @param  string  $string
45
     * @param  string  $style
46
     * @return void
47
     */
48
    public function line($string, $style = null)
49
    {
50
        $styled = $style ? "<$style>$string</$style>" : $string;
51
        $this->output->writeln($styled);
52
    }
53
54
    /**
55
     * Write a string as comment output.
56
     *
57
     * @param  string  $string
58
     * @return void
59
     */
60
    public function comment($string)
61
    {
62
        $this->line($string, 'comment');
63
    }
64
65
    /**
66
     * Write a string as question output.
67
     *
68
     * @param  string  $string
69
     * @return void
70
     */
71
    public function question($string)
72
    {
73
        $this->line($string, 'question');
74
    }
75
76
    /**
77
     * Write a string as error output.
78
     *
79
     * @param  string  $string
80
     * @return void
81
     */
82
    public function error($string)
83
    {
84
        $this->line($string, 'error');
85
    }
86
87
    /**
88
     * Get the value of a command argument.
89
     *
90
     * @param  string  $key
91
     * @return string|array
92
     */
93
    public function argument($key = null)
94
    {
95
        if (is_null($key)) {
96
            return $this->input->getArguments();
97
        }
98
        return $this->input->getArgument($key);
99
    }
100
101
    /**
102
     * Get the value of a command option.
103
     *
104
     * @param  string  $key
105
     * @return string|array
106
     */
107
    public function option($key = null)
108
    {
109
        if (is_null($key)) {
110
            return $this->input->getOptions();
111
        }
112
        return $this->input->getOption($key);
113
    }
114
}
115