JsonApiSerializerDeserializerTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A isArrayOfReference() 0 21 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\JsonApiPhp\Serialization;
6
7
trait JsonApiSerializerDeserializerTrait
8
{
9
    /**
10
     * @param mixed $element
11
     *
12
     * @return bool
13
     */
14
    abstract protected static function isReference($element): bool;
15
16
    /**
17
     * @param mixed $element
18
     * @param bool $all
19
     *
20
     * @return bool
21
     */
22 4
    private static function isArrayOfReference($element, bool $all = true): bool
23
    {
24 4
        if (false === is_array($element)) {
25 4
            return false;
26
        }
27
28 3
        if (true === empty($element)) {
29 2
            return false;
30
        }
31
32 3
        return array_reduce(
33 3
            $element,
34
            static function ($valid, $item) use ($all): bool {
35 3
                $isReference = static::isReference($item);
36 3
                if (true === $all) {
37 3
                    return true === $valid && true === $isReference;
38
                }
39
40 3
                return true === $valid || true === $isReference;
41 3
            },
42
            $all
43
        );
44
    }
45
}
46