Completed
Push — master ( 1be64b...a322af )
by Vladimir
03:02
created

ConsoleInterface   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 73.68%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 66
rs 10
ccs 14
cts 19
cp 0.7368
wmc 7
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOutputInterface() 0 4 1
A writeln() 0 4 1
A __construct() 0 10 3
A log() 0 7 2
1
<?php
2
3
namespace allejo\stakx\Core;
4
5
use Psr\Log\AbstractLogger;
6
use Symfony\Component\Console\Logger\ConsoleLogger;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class ConsoleInterface extends AbstractLogger
10
{
11
    /**
12
     * @var ConsoleLogger
13
     */
14
    private $logger;
15
16
    /**
17
     * @var OutputInterface
18
     */
19
    private $output;
20
21
    /**
22
     * ConsoleInterface constructor.
23
     *
24
     * @param ConsoleInterface|OutputInterface|null $output
25
     */
26 18
    public function __construct ($output = null)
27
    {
28 18
        $this->logger = null;
29
30 18
        if (!is_null($output))
31 18
        {
32 18
            $this->output = ($output instanceof ConsoleInterface) ? $output->getOutputInterface() : $output;
33 18
            $this->logger = new ConsoleLogger($this->output);
34 18
        }
35 18
    }
36
37
    /**
38
     * Return the OutputInterface object
39
     *
40
     * @return OutputInterface
41
     */
42
    public function getOutputInterface ()
43
    {
44
        return $this->output;
45
    }
46
47
    /**
48
     * Logs with an arbitrary level.
49
     *
50
     * @param mixed  $level
51
     * @param string $message
52
     * @param array  $context
53
     *
54
     * @return null
55
     */
56 3
    public function log ($level, $message, array $context = array())
57
    {
58 3
        if (!is_null($this->output))
59 3
        {
60 3
            $this->logger->log($level, $message, $context);
61 3
        }
62 3
    }
63
64
    /**
65
     * Writes a message to the output and adds a newline at the end.
66
     *
67
     * @param string|array $messages The message as an array of lines of a single string
68
     * @param int          $options  A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
69
     */
70
    public function writeln ($messages, $options = 0)
71
    {
72
        $this->output->writeln($messages, $options);
73
    }
74
}