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

IterableSource::matches()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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