OrPolicy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Policy;
6
7
use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface;
8
9
final class OrPolicy implements PolicyInterface
10
{
11
    /**
12
     * @var array|PolicyInterface[]
13
     */
14
    private $policies;
15
16
    /**
17
     * @param array|PolicyInterface[] $policies
18
     */
19 2
    public function __construct(array $policies)
20
    {
21 2
        $this->policies = $policies;
22 2
    }
23
24
    /**
25
     * @param object|mixed $object
26
     */
27
    public function isCompliant(DenormalizerContextInterface $context, $object): bool
28
    {
29
        foreach ($this->policies as $policy) {
30 2
            if ($policy->isCompliant($context, $object)) {
31
                return true;
32 2
            }
33 2
        }
34 2
35
        return false;
36
    }
37
}
38