LengthAggregator::tryAggregate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
6
7
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
8
use Remorhaz\JSON\Path\Value\LiteralScalarValue;
9
use Remorhaz\JSON\Data\Value\ValueInterface;
10
11
use function iterator_count;
12
13
final class LengthAggregator implements ValueAggregatorInterface
14
{
15
16 4
    public function tryAggregate(ValueInterface $value): ?ValueInterface
17
    {
18 4
        if (!$value instanceof ArrayValueInterface) {
19 1
            return null;
20
        }
21 3
        $length = iterator_count($value->createChildIterator());
22
23 3
        return new LiteralScalarValue($length);
24
    }
25
}
26