ArrayCollectionTraversalStrategy::traverse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Xsolve\Associate\CollectionTraversal;
4
5
use Xsolve\Associate\ObjectCollection\ObjectCollectionInterface;
6
7
class ArrayCollectionTraversalStrategy implements CollectionTraversalStrategyInterface
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function supports($propertyValue): bool
13
    {
14
        if (!is_array($propertyValue)) {
15
            return false;
16
        }
17
        if (empty($propertyValue)) {
18
            return true;
19
        }
20
21
        return array_keys($propertyValue) === range(0, count($propertyValue) - 1);
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function traverse(ObjectCollectionInterface $objectCollection, $propertyValue)
28
    {
29
        /* @var array $propertyValue */
30
        $objectCollection->addMany($propertyValue);
31
    }
32
}
33