Passed
Push — master ( e1f86a...4e1a3a )
by Siad
05:23
created

PrintStream   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 73
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A println() 0 4 1
A prints() 0 7 3
A write() 0 6 4
A __construct() 0 6 1
A newLine() 0 6 2
1
<?php
2
3
namespace Phing\Io;
4
5
/**
6
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
 *
18
 * This software consists of voluntary contributions made by many individuals
19
 * and is licensed under the LGPL. For more information please see
20
 * <http://phing.info>.
21
 */
22
class PrintStream
23
{
24
    /**
25
     * @var bool
26
     */
27
    private $autoFlush = false;
28
29
    /**
30
     * @var BufferedWriter
31
     */
32
    private $textOut;
33
34
    /**
35
     * @var OutputStream
36
     */
37
    protected $out;
38
39
    /**
40
     * @param OutputStream $out
41
     * @param bool $autoFlush
42
     */
43
    public function __construct(OutputStream $out, $autoFlush = false)
44
    {
45
        $this->out = $out;
46
        $this->autoFlush = $autoFlush;
47
48
        $this->textOut = new BufferedWriter(new OutputStreamWriter($out));
49
    }
50
51
    /**
52
     * @param mixed $value
53
     */
54
    public function println($value)
55
    {
56
        $this->prints($value);
57
        $this->newLine();
58
    }
59
60
    /**
61
     * @param mixed $value
62
     */
63
    public function prints($value)
64
    {
65
        if (is_bool($value)) {
66
            $value = $value === true ? 'true' : 'false';
67
        }
68
69
        $this->write((string) $value);
70
    }
71
72
    /**
73
     *
74
     */
75
    private function newLine()
76
    {
77
        $this->textOut->newLine();
78
79
        if ($this->autoFlush) {
80
            $this->textOut->flush();
81
        }
82
    }
83
84
    /**
85
     * @param string $buf
86
     * @param int $off
87
     * @param int $len
88
     */
89
    private function write($buf, $off = null, $len = null)
90
    {
91
        $this->textOut->write($buf, $off, $len);
92
93
        if ($this->autoFlush || $buff = '\n' && $this->autoFlush) {
0 ignored issues
show
Unused Code introduced by
The assignment to $buff is dead and can be removed.
Loading history...
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: $buff = ('\n' && $this->autoFlush), Probably Intended Meaning: ($buff = '\n') && $this->autoFlush
Loading history...
94
            $this->textOut->flush();
95
        }
96
    }
97
}
98