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

OutputAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A verbosityMeetsThreshold() 0 10 2
A writeMessage() 0 4 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