Passed
Push — master ( f13532...bf7dba )
by Andrea Marco
02:44 queued 12s
created

IterableSource   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 3 2
A calculateSize() 0 3 2
A getIterator() 0 3 1
1
<?php
2
3
namespace Cerbero\JsonParser\Sources;
4
5
use Traversable;
6
7
use function is_array;
8
use function count;
9
10
/**
11
 * The iterable source.
12
 *
13
 * @property-read iterable $source
14
 */
15
class IterableSource extends Source
16
{
17
    /**
18
     * Retrieve the JSON fragments
19
     *
20
     * @return Traversable<int, string>
21
     */
22 1
    public function getIterator(): Traversable
23
    {
24 1
        yield from $this->source;
25
    }
26
27
    /**
28
     * Determine whether the JSON source can be handled
29
     *
30
     * @return bool
31
     */
32 330
    public function matches(): bool
33
    {
34 330
        return is_iterable($this->source) && !$this->source instanceof Source;
35
    }
36
37
    /**
38
     * Retrieve the calculated size of the JSON source
39
     *
40
     * @return int|null
41
     */
42 1
    protected function calculateSize(): ?int
43
    {
44 1
        return is_array($this->source) ? count($this->source) : iterator_count(clone $this->source);
45
    }
46
}
47