PrefixFormatter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * For licensing information, please see the LICENSE file accompanied with this file.
4
 *
5
 * @author Gerard van Helden <[email protected]>
6
 * @copyright 2012 Gerard van Helden <http://melp.nl>
7
 */
8
9
namespace Zicht\Tool\Output;
10
11
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
12
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
13
14
class PrefixFormatter implements OutputFormatterInterface
15
{
16
    public $prefix = '';
17
18
    public function __construct(OutputFormatterInterface $innerFormatter)
19
    {
20
        $this->innerFormatter = $innerFormatter;
0 ignored issues
show
Bug introduced by
The property innerFormatter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
    }
22
23
24
    /**
25
     * @{inheritDoc}
26
     */
27
    public function setDecorated($decorated)
28
    {
29
        return $this->innerFormatter->setDecorated($decorated);
30
    }
31
32
    /**
33
     * @{inheritDoc}
34
     */
35
    public function isDecorated()
36
    {
37
        return $this->innerFormatter->isDecorated();
38
    }
39
40
    /**
41
     * @{inheritDoc}
42
     */
43
    public function setStyle($name, OutputFormatterStyleInterface $style)
44
    {
45
        return $this->innerFormatter->setStyle($name, $style);
46
    }
47
48
    /**
49
     * @{inheritDoc}
50
     */
51
    public function hasStyle($name)
52
    {
53
        return $this->innerFormatter->hasStyle($name);
54
    }
55
56
    /**
57
     * @{inheritDoc}
58
     */
59
    public function getStyle($name)
60
    {
61
        return $this->innerFormatter->getStyle($name);
62
    }
63
64
    /**
65
     * @{inheritDoc}
66
     */
67
    public function format($message)
68
    {
69
        $ret = $this->innerFormatter->format($message);
70
71
        if ($this->prefix) {
72
            $ret = preg_replace('/^/m', $this->prefix . '$1', $ret);
73
        }
74
        return $ret;
75
    }
76
}