Completed
Push — master ( 9b8d1b...94a688 )
by Michael
06:16
created

Output::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Schnittstabil\Dartisan;
4
5
class Output implements Contracts\Output
6
{
7
    /**
8
     * @var callable
9
     */
10
    protected $outputFormatter;
11
12
    /**
13
     * @param callable $outputFormatter
14
     */
15
    public function __construct(callable $outputFormatter = null)
16
    {
17
        $this->outputFormatter = $outputFormatter;
18
    }
19
20
    /**
21
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
22
     * @param $message
23
     * @param bool $eol
24
     */
25
    public function raw(string $message, bool $eol = true): void
26
    {
27
        if ($outputFormatter = $this->outputFormatter) {
28
            $message = $outputFormatter($message);
29
        }
30
31
        if ($eol) {
32
            $message .= PHP_EOL;
33
        }
34
35
        echo $message;
36
    }
37
38
    /**
39
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
40
     * @param string $msg
41
     * @param bool $eol
42
     */
43
    public function error(string $msg, bool $eol = true): void
44
    {
45
        $this->raw("<error>$msg</error>", $eol);
46
    }
47
48
    /**
49
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
50
     * @param string $msg
51
     * @param bool $eol
52
     */
53
    public function info(string $msg, bool $eol = true): void
54
    {
55
        $this->raw('<info>'.$msg.'</info>', $eol);
56
    }
57
}
58