Passed
Push — master ( 3d58fd...651f47 )
by Edward
05:09
created

LengthAggregator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A tryAggregate() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Runtime\Aggregator;
5
6
use function iterator_count;
7
use Remorhaz\JSON\Data\Value\ArrayValueInterface;
8
use Remorhaz\JSON\Path\Value\LiteralScalarValue;
9
use Remorhaz\JSON\Data\Value\ValueInterface;
10
11
final class LengthAggregator implements ValueAggregatorInterface
12
{
13
14 4
    public function tryAggregate(ValueInterface $value): ?ValueInterface
15
    {
16 4
        if (!$value instanceof ArrayValueInterface) {
17 1
            return null;
18
        }
19 3
        $length = iterator_count($value->createChildIterator());
20
21 3
        return new LiteralScalarValue($length);
22
    }
23
}
24