StringSource::isEof()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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