Message   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 57
ccs 13
cts 15
cp 0.8667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A __toString() 0 4 1
A output() 0 4 1
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Behat\DebugExtension;
6
7
use Symfony\Component\Console\Output\ConsoleOutput;
8
9
/**
10
 * Class Message.
11
 *
12
 * @package Behat\DebugExtension
13
 */
14
class Message
15
{
16
    /**
17
     * @var string
18
     */
19
    private $message = '';
20
    /**
21
     * @var ConsoleOutput
22
     */
23
    private static $console;
24
25
    /**
26
     * Message constructor.
27
     *
28
     * @link http://symfony.com/doc/current/components/console/introduction.html#coloring-the-output
29
     *
30
     * @param string $type
31
     *   Could be "comment", "info", "question" or "error".
32
     * @param int $indent
33
     *   Number of spaces.
34
     * @param string[] $strings
35
     *   Paragraphs.
36
     * @param string[] $placeholders
37
     *   Any replacement argument for "sprintf()".
38
     * @param bool $output
39
     *   Print message or not.
40
     */
41 4
    public function __construct($type, $indent, array $strings, array $placeholders = [], $output = true)
42
    {
43 4
        $indent = implode(' ', array_fill_keys(range(0, $indent), '')) . "<$type>";
44 4
        $this->message = vsprintf($indent . implode("\n</$type>$indent", $strings) . "</$type>", $placeholders);
45
46 4
        if (null === self::$console) {
47 4
            self::$console = new ConsoleOutput();
48 4
        }
49
50 4
        if ($output) {
51
            $this->output();
52
        }
53 4
    }
54
55
    /**
56
     * @return string
57
     */
58 4
    public function __toString()
59
    {
60 4
        return $this->message;
61
    }
62
63
    /**
64
     * Print message to command line.
65
     */
66 4
    public function output()
67
    {
68 4
        self::$console->writeln($this->message);
69 4
    }
70
}
71