StringReader::getResource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Io;
22
23
/**
24
 * Dummy class for reading from string of characters.
25
 */
26
class StringReader extends Reader
27
{
28
    /**
29
     * @var string
30
     */
31
    private $string;
32
33
    /**
34
     * @var int
35
     */
36
    private $mark = 0;
37
38
    /**
39
     * @var int
40
     */
41
    private $currPos = 0;
42
43
    /**
44
     * @param $string
45
     */
46
    public function __construct($string)
47
    {
48
        $this->string = $string;
49
    }
50
51
    /**
52
     * @param int $n
53
     */
54
    public function skip($n)
55
    {
56
    }
57
58
    /**
59
     * @param null $len
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $len is correct as it would always require null to be passed?
Loading history...
60
     *
61
     * @return int|string
62
     */
63
    public function read($len = null)
64
    {
65
        if (null === $len) {
0 ignored issues
show
introduced by
The condition null === $len is always true.
Loading history...
66
            return $this->string;
67
        }
68
69
        if ($this->currPos >= strlen($this->string)) {
70
            return -1;
71
        }
72
        $out = substr($this->string, $this->currPos, $len);
73
        $this->currPos += $len;
74
75
        return $out;
76
    }
77
78
    public function mark()
79
    {
80
        $this->mark = $this->currPos;
81
    }
82
83
    public function reset()
84
    {
85
        $this->currPos = $this->mark;
86
    }
87
88
    public function close()
89
    {
90
    }
91
92
    public function open()
93
    {
94
    }
95
96
    /**
97
     * @return bool
98
     */
99
    public function ready()
100
    {
101
        return true;
102
    }
103
104
    /**
105
     * @return bool
106
     */
107
    public function markSupported()
108
    {
109
        return true;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getResource()
116
    {
117
        return '(string) "' . $this->string . '"';
118
    }
119
}
120