Passed
Push — master ( 0f10a6...8f1e95 )
by Koen
11:27
created

InputStream   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 51
ccs 17
cts 17
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A next() 0 10 2
A peek() 0 3 1
A eof() 0 3 1
A error() 0 3 1
1
<?php
2
3
namespace Vlaswinkel\Lua;
4
5
/**
6
 * Class InputStream
7
 *
8
 * @see     http://lisperator.net/pltut/parser/input-stream
9
 *
10
 * @author  Koen Vlaswinkel <[email protected]>
11
 * @package Vlaswinkel\Lua
12
 */
13
class InputStream {
14
    /**
15
     * @var string
16
     */
17
    private $input;
18
19
    /**
20
     * @var int
21
     */
22
    private $position = 0;
23
    /**
24
     * @var int
25
     */
26
    private $line = 1;
27
    /**
28
     * @var int
29
     */
30
    private $column = 0;
31
32
    /**
33
     * InputStream constructor.
34
     *
35
     * @param string $input
36
     */
37 27
    public function __construct($input) {
38 27
        $this->input = $input;
39 27
    }
40
41 26
    public function next() {
42 26
        $char = $this->input[$this->position++];
43 26
        if ($char == "\n") {
44 5
            $this->line++;
45 5
            $this->column = 0;
46 5
        } else {
47 26
            $this->column++;
48
        }
49 26
        return $char;
50
    }
51
52 21
    public function peek() {
53 21
        return $this->input[$this->position];
54
    }
55
56 22
    public function eof() {
57 22
        return $this->position >= strlen($this->input);
58
    }
59
60 6
    public function error($msg) {
61 6
        throw new ParseException($msg . ' (' . $this->line . ':' . $this->column . ')');
62
    }
63
}