Completed
Pull Request — master (#533)
by Greg
03:06
created

OutputAdapter::writeMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Robo\Common;
3
4
use Robo\Contract\OutputAdapterInterface;
5
use Robo\Contract\OutputAwareInterface;
6
use Robo\Contract\VerbosityThresholdInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Adapt OutputInterface or other output function to the VerbosityThresholdInterface.
11
 */
12
class OutputAdapter implements OutputAdapterInterface, OutputAwareInterface
13
{
14
    use OutputAwareTrait;
15
16
    protected $verbosityMap = [
17
        VerbosityThresholdInterface::VERBOSITY_NORMAL => OutputInterface::VERBOSITY_NORMAL,
18
        VerbosityThresholdInterface::VERBOSITY_VERBOSE => OutputInterface::VERBOSITY_VERBOSE,
19
        VerbosityThresholdInterface::VERBOSITY_VERY_VERBOSE => OutputInterface::VERBOSITY_VERY_VERBOSE,
20
        VerbosityThresholdInterface::VERBOSITY_DEBUG => OutputInterface::VERBOSITY_DEBUG,
21
    ];
22
23
    public function verbosityMeetsThreshold($verbosityThreshold)
24
    {
25
        if (!isset($this->verbosityMap[$verbosityThreshold])) {
26
            return true;
27
        }
28
        $verbosityThreshold = $this->verbosityMap[$verbosityThreshold];
29
        $verbosity = $this->output()->getVerbosity();
30
31
        return $verbosity >= $verbosityThreshold;
32
    }
33
34
    public function writeMessage($message)
35
    {
36
        $this->output()->write($message);
37
    }
38
}
39