Completed
Push — master ( 271466...84e0b1 )
by Neomerx
01:17
created

ConsoleIoWrapper::writeInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php namespace Limoncello\Commands\Wrappers;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Commands\IoInterface;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * @package Limoncello\Commands
25
 */
26
class ConsoleIoWrapper implements IoInterface
27
{
28
    /**
29
     * @var InputInterface
30
     */
31
    private $input;
32
33
    /**
34
     * @var OutputInterface
35
     */
36
    private $output;
37
38
    /**
39
     * @param InputInterface  $input
40
     * @param OutputInterface $output
41
     */
42 11
    public function __construct(InputInterface $input, OutputInterface $output)
43
    {
44 11
        $this->input  = $input;
45 11
        $this->output = $output;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 4
    public function hasArgument(string $name): bool
52
    {
53 4
        return $this->getInput()->hasArgument($name);
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59 8
    public function getArgument(string $name)
60
    {
61 8
        return $this->getInput()->getArgument($name);
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 1
    public function getArguments(): array
68
    {
69 1
        return $this->getInput()->getArguments();
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75 1
    public function hasOption(string $name): bool
76
    {
77 1
        return $this->getInput()->hasOption($name);
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83 1
    public function getOption(string $name)
84
    {
85 1
        return $this->getInput()->getOption($name);
86
    }
87
88
    /**
89
     * @inheritdoc
90
     */
91 1
    public function getOptions(): array
92
    {
93 1
        return $this->getInput()->getOptions();
94
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99 3 View Code Duplication
    public function writeInfo(string $message, int $verbosity = self::VERBOSITY_NORMAL): IoInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101 3
        $isNewLine = false;
102 3
        $options   = $this->convertVerbosityLevel($verbosity);
103 3
        $this->getOutput()->write("<info>$message</info>", $isNewLine, $options);
104
105 3
        return $this;
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111 1 View Code Duplication
    public function writeWarning(string $message, int $verbosity = self::VERBOSITY_NORMAL): IoInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113 1
        $isNewLine = false;
114 1
        $options   = $this->convertVerbosityLevel($verbosity);
115 1
        $this->getOutput()->write("<comment>$message</comment>", $isNewLine, $options);
116
117 1
        return $this;
118
    }
119
120
    /**
121
     * @inheritdoc
122
     */
123 5 View Code Duplication
    public function writeError(string $message, int $verbosity = self::VERBOSITY_NORMAL): IoInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125 5
        $isNewLine = false;
126 5
        $options   = $this->convertVerbosityLevel($verbosity);
127 5
        $this->getOutput()->write("<error>$message</error>", $isNewLine, $options);
128
129 5
        return $this;
130
    }
131
132
    /**
133
     * @return OutputInterface
134
     */
135 8
    protected function getOutput(): OutputInterface
136
    {
137 8
        return $this->output;
138
    }
139
140
    /**
141
     * @return InputInterface
142
     */
143 9
    protected function getInput(): InputInterface
144
    {
145 9
        return $this->input;
146
    }
147
148
    /**
149
     * @param int $verbosity
150
     *
151
     * @return int
152
     */
153 9
    protected function convertVerbosityLevel(int $verbosity): int
154
    {
155
        switch ($verbosity) {
156 9
            case static::VERBOSITY_QUIET:
157 1
                $result = OutputInterface::VERBOSITY_QUIET;
158 1
                break;
159 9
            case static::VERBOSITY_NORMAL:
160 9
                $result = OutputInterface::VERBOSITY_NORMAL;
161 9
                break;
162 3
            case static::VERBOSITY_VERBOSE:
163 3
                $result = OutputInterface::VERBOSITY_VERBOSE;
164 3
                break;
165 1
            case static::VERBOSITY_VERY_VERBOSE:
166 1
                $result = OutputInterface::VERBOSITY_VERY_VERBOSE;
167 1
                break;
168
            default:
169 1
                $result = OutputInterface::VERBOSITY_NORMAL;
170 1
                break;
171
        }
172
173 9
        return $result;
174
    }
175
}
176