Test Failed
Branch master (b3e807)
by Alexey
03:28
created

AbstractCommand::configure()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 4
nop 0
1
<?php
2
3
namespace Venta\Console;
4
5
use Symfony\Component\Console\Command\Command as SymfonyCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Venta\Console\Command\SignatureParser;
9
10
/**
11
 * Class AbstractCommand
12
 *
13
 * @package Venta\Console
14
 */
15
abstract class AbstractCommand extends SymfonyCommand
16
{
17
    /**
18
     * The command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = '';
23
24
    /**
25
     * The Input implementation.
26
     *
27
     * @var InputInterface
28
     */
29
    protected $input;
30
31
    /**
32
     * The Output implementation.
33
     *
34
     * @var OutputInterface
35
     */
36
    protected $output;
37
38
    /**
39
     * The command signature.
40
     *
41
     * @var string
42
     */
43
    protected $signature = '';
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    final public function run(InputInterface $input, OutputInterface $output)
49
    {
50
        $this->input = $input;
51
        $this->output = $output;
52
53
        return parent::run($input, $output);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function configure()
60
    {
61
        $signature = (new SignatureParser())->parse($this->signature);
62
63
        $this->setName($signature['name']);
64
        $this->setDescription($this->description);
65
66
        foreach ($signature['arguments'] as $argument) {
67
            $this->addArgument(
68
                $argument['name'],
69
                $argument['type'],
70
                $argument['description'],
71
                $argument['default']
72
            );
73
        }
74
75
        foreach ($signature['options'] as $option) {
76
            $this->addOption($option['name'], null, $option['type'], $option['description'], $option['default']);
77
        }
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    final protected function execute(InputInterface $input, OutputInterface $output)
84
    {
85
        return $this->handle();
86
    }
87
88
    /**
89
     * The command handler.
90
     *
91
     * @return int Exit code.
92
     */
93
    abstract protected function handle();
94
}