Passed
Push — master ( 4e4741...4fd99d )
by Asmir
03:38 queued 01:04
created

ExclusionPolicy::__construct()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 7.7656

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 24
nop 2
dl 0
loc 27
rs 8.8333
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
crap 7.7656
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Annotation;
6
7
use JMS\Serializer\Exception\RuntimeException;
8
9
/**
10
 * @Annotation
11
 * @Target("CLASS")
12
 */
13
#[\Attribute(\Attribute::TARGET_CLASS)]
14
final class ExclusionPolicy
15
{
16
    public const NONE = 'NONE';
17
    public const ALL = 'ALL';
18
19
    /**
20 25
     * @var string|null
21
     */
22 25
    public $policy = null;
23
24
    public function __construct(array $values = [], ?string $policy = null)
25
    {
26 25
        $value = self::NONE;
27
28 25
        if (array_key_exists('value', $values)) {
29
            $value = $values['value'];
30
        }
31 25
32
        if (array_key_exists('policy', $values)) {
33
            $value = $values['policy'];
34
        }
35
36
        if (null !== $policy) {
37
            $value = $policy;
38
        }
39
40
        if (!\is_string($value)) {
41
            throw new RuntimeException('Exclusion policy value must be of string type.');
42
        }
43
44
        $value = strtoupper($value);
45
46
        if (self::NONE !== $value && self::ALL !== $value) {
47
            throw new RuntimeException('Exclusion policy must either be "ALL", or "NONE".');
48
        }
49
50
        $this->policy = $value;
51
    }
52
}
53