Completed
Push — master ( f46321...378618 )
by Greg
03:20
created

OutputAdapter::verbosityMeetsThreshold()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
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