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

Output   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A raw() 0 12 3
A error() 0 4 1
A info() 0 4 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