Json   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 34
ccs 7
cts 7
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 3 3
A calculateSize() 0 3 1
A getIterator() 0 4 2
1
<?php
2
3
namespace Cerbero\JsonParser\Sources;
4
5
use Cerbero\JsonParser\Concerns\DetectsEndpoints;
6
use Traversable;
7
8
use function is_string;
9
use function strlen;
10
11
/**
12
 * The JSON source.
13
 *
14
 * @property-read string $source
15
 */
16
class Json extends Source
17
{
18
    use DetectsEndpoints;
19
20
    /**
21
     * Retrieve the JSON fragments
22
     *
23
     * @return Traversable<int, string>
24
     */
25 331
    public function getIterator(): Traversable
26
    {
27 331
        for ($i = 0; $i < $this->size(); $i += $this->config->bytes) {
28 331
            yield substr($this->source, $i, $this->config->bytes);
29
        }
30
    }
31
32
    /**
33
     * Determine whether the JSON source can be handled
34
     *
35
     * @return bool
36
     */
37 330
    public function matches(): bool
38
    {
39 330
        return is_string($this->source) && !is_file($this->source) && !$this->isEndpoint($this->source);
40
    }
41
42
    /**
43
     * Retrieve the calculated size of the JSON source
44
     *
45
     * @return int|null
46
     */
47 331
    protected function calculateSize(): ?int
48
    {
49 331
        return strlen($this->source);
50
    }
51
}
52