Passed
Pull Request — master (#1337)
by Asmir
02:42
created

ExclusionPolicy::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 2
cts 3
cp 0.6667
crap 3.3332
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
    use AnnotationUtilsTrait;
17
    use AnnotationUtilsTrait;
18
19
    public const NONE = 'NONE';
20 25
    public const ALL = 'ALL';
21
22 25
    /**
23
     * @var string|null
24
     */
25
    public $policy = 'NONE';
26 25
27
    public function __construct($values = [], ?string $policy = null)
28 25
    {
29
        $this->loadAnnotationParameters(get_defined_vars());
30
31 25
        $this->policy = strtoupper($this->policy);
0 ignored issues
show
Bug introduced by
It seems like $this->policy can also be of type null; however, parameter $string of strtoupper() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $this->policy = strtoupper(/** @scrutinizer ignore-type */ $this->policy);
Loading history...
32
33
        if (self::NONE !== $this->policy && self::ALL !== $this->policy) {
34
            throw new RuntimeException('Exclusion policy must either be "ALL", or "NONE".');
35
        }
36
    }
37
}
38