Completed
Push — master ( 5c652a...e01a7c )
by Henri
03:49
created

NamespaceExposingTurtleParser::getNamespaces()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class NamespaceExposingTurtleParser extends EasyRdf_Parser_Turtle
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private $bytePos = 0;
6
    private $dataLength = null;
7
8
    /**
9
     * Returns the namespace prefixes as an array of prefix => URI
10
     * @return array $namespaces
11
     */
12
    public function getNamespaces()
13
    {
14
        return $this->namespaces;
15
    }
16
17
    /**
18
     * A lot faster since we're now only reading the next 4 bytes 
19
     * instead of the whole string.
20
     * Gets the next character to be returned by read().
21
     */
22
    protected function peek()
23
    {
24
        if(!$this->dataLength) { $this->dataLength = strlen($this->data); }
25
        if ($this->dataLength > $this->bytePos) {
26
            $slice = substr($this->data, $this->bytePos, 4);
27
            return mb_substr($slice, 0, 1, "UTF-8");
28
        } else {
29
            return -1;
30
        }
31
    }
32
33
    /**
34
     * Does not manipulate the data variable. Keeps track of the
35
     * byte position instead.
36
     * Read a single character from the input buffer.
37
     * Returns -1 when the end of the file is reached.
38
     */
39
    protected function read()
40
    {
41
        $char = $this->peek();
42
        if ($char == -1) {
43
            return -1;
44
        }
45
        $this->bytePos += strlen($char);
46
        // Keep tracks of which line we are on (0A = Line Feed)
47
        if ($char == "\x0A") {
48
            $this->line += 1;
49
            $this->column = 1;
50
        } else {
51
            $this->column += 1;
52
        }
53
        return $char;
54
    }
55
56
    /**
57
     * Steps back, restoring the previous character or statement read() to the input buffer
58
     */
59
    protected function unread($chars)
60
    {
61
        if ($this->column > 0) {
62
            $this->column -= mb_strlen($chars, "UTF-8");
63
            $this->bytePos -= strlen($chars);
64
            if ($this->bytePos < 0) {
65
                $this->bytePos = 0;
66
            }
67
        }
68
    }
69
}
70