StringSource   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 9
c 2
b 1
f 0
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A read() 0 5 1
A rewind() 0 3 1
A isEof() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace JsonDecodeStream\Source;
5
6
class StringSource implements SourceInterface
7
{
8
    /** @var string */
9
    protected $string;
10
    /** @var int */
11
    protected $position = 0;
12
13 71
    public function __construct(string $string)
14
    {
15 71
        $this->string = $string;
16 71
    }
17
18 63
    public function isEof(): bool
19
    {
20 63
        return $this->position == strlen($this->string);
21
    }
22
23 63
    public function read(int $bytes): string
24
    {
25 63
        $part = substr($this->string, $this->position, $bytes);
26 63
        $this->position += strlen($part);
27 63
        return $part;
28
    }
29
30 62
    public function rewind(): void
31
    {
32 62
        $this->position = 0;
33 62
    }
34
}
35