Completed
Push — dev ( 122982...5e45c8 )
by Zach
02:18
created

Command   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 120
rs 10
c 0
b 0
f 0
wmc 11
lcom 2
cbo 4

7 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 2
A execute() 0 10 2
A getOutput() 0 4 1
A argument() 0 8 2
A hasArgument() 0 4 1
A option() 0 8 2
A hasOption() 0 4 1
1
<?php
2
3
namespace Yarak\Console;
4
5
use Yarak\Console\Output\SymfonyOutput;
6
use Yarak\Console\Command\SignatureParser;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Command\Command as SymfonyCommand;
10
11
abstract class Command extends SymfonyCommand
12
{
13
    /**
14
     * Symfony console output.
15
     *
16
     * @var SymfonyOutput
17
     */
18
    protected $output;
19
20
    /**
21
     * Symfony input implementation.
22
     *
23
     * @var InputInterface
24
     */
25
    protected $input;
26
27
    /**
28
     * The command description.
29
     *
30
     * @var string
31
     */
32
    protected $description;
33
34
    /**
35
     * Configure the command if signature is set.
36
     */
37
    protected function configure()
38
    {
39
        if (isset($this->signature)) {
40
            $parser = new SignatureParser($this);
41
42
            $parser->parse($this->signature);
0 ignored issues
show
Bug introduced by
The property signature does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
44
            $this->setDescription($this->description);
45
        }
46
    }
47
48
    /**
49
     * Execute the command.
50
     *
51
     * @param InputInterface  $input
52
     * @param OutputInterface $output
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $this->output = new SymfonyOutput($output);
57
58
        $this->input = $input;
59
60
        if (method_exists($this, 'handle')) {
61
            $this->handle();
62
        }
63
    }
64
65
    /**
66
     * Return the output implementation.
67
     *
68
     * @return SymfonyOutput
69
     */
70
    protected function getOutput()
71
    {
72
        return $this->output;
73
    }
74
75
    /**
76
     * Get the value of a command argument.
77
     *
78
     * @param string $key
79
     *
80
     * @return string|array
81
     */
82
    protected function argument($key = null)
83
    {
84
        if (is_null($key)) {
85
            return $this->input->getArguments();
86
        }
87
88
        return $this->input->getArgument($key);
89
    }
90
91
    /**
92
     * Determine if the given argument is present.
93
     *
94
     * @param string|int $name
95
     *
96
     * @return bool
97
     */
98
    protected function hasArgument($name)
99
    {
100
        return $this->input->hasArgument($name);
101
    }
102
103
    /**
104
     * Get the value of a command option.
105
     *
106
     * @param string $key
107
     *
108
     * @return string|array
109
     */
110
    protected function option($key = null)
111
    {
112
        if (is_null($key)) {
113
            return $this->input->getOptions();
114
        }
115
116
        return $this->input->getOption($key);
117
    }
118
119
    /**
120
     * Determine if the given option is present.
121
     *
122
     * @param string $name
123
     *
124
     * @return bool
125
     */
126
    protected function hasOption($name)
127
    {
128
        return $this->input->hasOption($name);
129
    }
130
}
131