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

ConsoleReader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 58
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A eof() 0 3 1
A close() 0 2 1
A read() 0 5 1
A getResource() 0 3 1
A readLine() 0 6 1
A open() 0 2 1
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
namespace Phing\Io;
21
22
/**
23
 * Convenience class for reading console input.
24
 *
25
 * @author  Hans Lellelid <[email protected]>
26
 * @author  Matthew Hershberger <[email protected]>
27
 * @package phing.system.io
28
 */
29
class ConsoleReader extends Reader
30
{
31
32
    /**
33
     * @return string
34
     */
35
    public function readLine()
36
    {
37
        $out = fgets(STDIN); // note: default maxlen is 1kb
38
        $out = rtrim($out);
39
40
        return $out;
41
    }
42
43
    /**
44
     *
45
     * @param  int $len Num chars to read.
46
     * @return string chars read or -1 if eof.
47
     */
48
    public function read($len = null)
49
    {
50
        $out = fread(STDIN, $len);
0 ignored issues
show
Bug introduced by
It seems like $len can also be of type null; however, parameter $length of fread() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        $out = fread(STDIN, /** @scrutinizer ignore-type */ $len);
Loading history...
51
52
        return $out;
53
        // FIXME
54
        // read by chars doesn't work (yet?) with PHP stdin.  Maybe
55
        // this is just a language feature, maybe there's a way to get
56
        // ability to read chars w/o <enter> ?
57
    }
58
59
    public function close()
60
    {
61
        // STDIN is always open
62
    }
63
64
    public function open()
65
    {
66
        // STDIN is always open
67
    }
68
69
    /**
70
     * Whether eof has been reached with stream.
71
     *
72
     * @return boolean
73
     */
74
    public function eof()
75
    {
76
        return feof(STDIN);
77
    }
78
79
    /**
80
     * Returns path to file we are reading.
81
     *
82
     * @return string
83
     */
84
    public function getResource()
85
    {
86
        return "console";
87
    }
88
}
89