GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 2c0c61...f17d70 )
by Alexander
05:03
created

Context   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 117
ccs 29
cts 33
cp 0.8788
rs 10
c 1
b 0
f 0
wmc 11
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setString() 0 7 1
A value() 0 10 2
A getCursor() 0 4 1
A setCursor() 0 7 2
A increaseDepth() 0 4 1
A decreaseDepth() 0 7 2
A error() 0 4 1
1
<?php
2
/**
3
 * @author  Alexander Getmanskii <[email protected]>
4
 * @package GetSky\ParserExpressions
5
 */
6
namespace GetSky\ParserExpressions;
7
8
use Exception;
9
10
/**
11
 * It is a wrapper for parsing string.
12
 */
13
class Context
14
{
15
    /**
16
     * @var string Parsing string.
17
     */
18
    protected $string;
19
20
    /**
21
     * @var int The number of the current position.
22
     */
23
    protected $cursor = 0;
24
25
    /**
26
     * @var int The current depth of immersion in the rules tree.
27
     */
28
    protected $depth = 0;
29
30
    /**
31
     * @var ErrorCollectionInterface
32
     */
33
    protected $errors;
34
35
    /**
36
     * @param ErrorCollectionInterface $errorCollection
37
     */
38 2
    public function __construct(ErrorCollectionInterface $errorCollection)
39
    {
40 2
        $this->errors = $errorCollection;
41 2
    }
42
43
    /**
44
     * Set new string and reset cursor.
45
     *
46
     * @param string $string
47
     * @return void
48
     */
49 2
    public function setString($string)
50
    {
51 2
        $this->string = (string) $string;
52 2
        $this->cursor = 0;
53 2
        $this->depth = 0;
54 2
        $this->errors->clear();
55 2
    }
56
57
    /**
58
     * Returns the characters from the current position with the given $size.
59
     *
60
     * @param int $size
61
     * @return bool|string
62
     */
63 3
    public function value($size = 1)
64
    {
65 3
        if ($this->cursor + $size > strlen($this->string)) {
66 1
            return false;
67
        }
68 2
        $value = substr($this->string, $this->cursor, $size);
69 2
        $this->cursor += $size;
70
71 2
        return $value;
72
    }
73
74
    /**
75
     * Returns the current value of the cursor.
76
     *
77
     * @return int
78
     */
79 3
    public function getCursor()
80
    {
81 3
        return $this->cursor;
82
    }
83
84
    /**
85
     * Sets a new value for the cursor.
86
     *
87
     * @param int $position
88
     * @throws Exception
89
     */
90 4
    public function setCursor($position)
91
    {
92 4
        if ($position < 0) {
93 1
            throw new Exception('The cursor can\'t be negative.');
94
        }
95 3
        $this->cursor = $position;
96 3
    }
97
98
    /**
99
     * Increase the depth by one.
100
     *
101
     * @throws Exception
102
     */
103 7
    public function increaseDepth()
104
    {
105 7
        $this->depth++;
106 7
    }
107
108
    /**
109
     * Decrease the depth by one.
110
     *
111
     * @throws Exception
112
     */
113 7
    public function decreaseDepth()
114
    {
115 7
        if ($this->depth == 0) {
116
            throw new Exception('The depth can\'t be negative.');
117
        }
118 7
        $this->depth--;
119 7
    }
120
121
    /**
122
     * @param RuleInterface $rule
123
     * @param int $index
124
     */
125
    public function error(RuleInterface $rule, $index)
126
    {
127
        $this->errors->add($rule, $index, $this->depth);
128
    }
129
}
130