Completed
Push — master ( 2a88b7...1fad07 )
by Vladimir
06:33
created

Command   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 128
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
wmc 11
lcom 2
cbo 4

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 7 1
A getArgument() 0 4 1
A line() 0 4 1
A success() 0 4 1
A info() 0 4 1
A warning() 0 4 1
A error() 0 4 1
A input() 0 4 1
A confirm() 0 4 1
A filesystem() 0 4 1
handle() 0 1 ?
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt;
6
7
use League\Flysystem\Filesystem;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Command\Command as SymfonyCommand;
12
13
abstract class Command extends SymfonyCommand
14
{
15
    protected $kernel;
16
17
    /** @var InputInterface */
18
    protected $input;
19
20
    /** @var SymfonyStyle */
21
    protected $output;
22
23
    public function __construct(Kernel $kernel)
24
    {
25
        parent::__construct();
26
27
        $this->kernel = $kernel;
28
    }
29
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $this->input = $input;
33
        $this->output = new SymfonyStyle($input, $output);
34
35
        $this->handle();
36
    }
37
38
    /**
39
     * Get argument value.
40
     *
41
     * @param string $name
42
     *
43
     * @return mixed
44
     *
45
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
46
     */
47
    protected function getArgument(string $name)
48
    {
49
        return $this->input->getArgument($name);
50
    }
51
52
    /**
53
     * Write a message.
54
     *
55
     * @param string $message
56
     */
57
    protected function line(string $message): void
58
    {
59
        $this->output->writeln($message);
60
    }
61
62
    /**
63
     * Display success message.
64
     *
65
     * @param string $message
66
     */
67
    protected function success(string $message): void
68
    {
69
        $this->output->success($message);
70
    }
71
72
    /**
73
     * Display info message.
74
     *
75
     * @param string $message
76
     */
77
    protected function info(string $message): void
78
    {
79
        $this->output->writeln('<info>'.$message.'</info>');
80
    }
81
82
    /**
83
     * Display warning message.
84
     *
85
     * @param string $message
86
     */
87
    protected function warning(string $message): void
88
    {
89
        $this->output->writeln('<warning>'.$message.'</warning>');
90
    }
91
92
    /**
93
     * Display error message.
94
     *
95
     * @param string $message
96
     */
97
    protected function error(string $message): void
98
    {
99
        $this->output->writeln('<error>'.$message.'</error>');
100
    }
101
102
    /**
103
     * Prompt the user for input.
104
     *
105
     * @param string $message
106
     *
107
     * @return string
108
     */
109
    protected function input(string $message): string
110
    {
111
        return $this->output->ask($message);
112
    }
113
114
    /**
115
     * Display confirmation input.
116
     *
117
     * @param string $message
118
     *
119
     * @return bool
120
     */
121
    protected function confirm(string $message): bool
122
    {
123
        return $this->output->confirm($message, false);
124
    }
125
126
    /**
127
     * Get filesystem instance.
128
     *
129
     * @return Filesystem
130
     */
131
    protected function filesystem(): Filesystem
132
    {
133
        return $this->kernel->resolve(Filesystem::class);
134
    }
135
136
    /**
137
     * Handle command.
138
     */
139
    abstract public function handle(): void;
140
}
141