Passed
Push — master ( 984276...7580af )
by Vladimir
03:02
created

Command::success()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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