setResetMissingFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 10
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Denormalizer;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
9
final class DenormalizerContextBuilder implements DenormalizerContextBuilderInterface
10
{
11
    /**
12
     * @var array|null
13
     */
14
    private $allowedAdditionalFields;
15
16
    /**
17
     * @deprecated
18
     *
19
     * @var string[]
20
     */
21
    private $groups = [];
22
23
    /**
24
     * @var ServerRequestInterface|null
25
     */
26
    private $request;
27
28
    /**
29
     * @var bool
30
     */
31
    private $resetMissingFields = false;
32
33
    /**
34
     * @var array
35
     */
36
    private $attributes = [];
37
38 4
    private function __construct()
39
    {
40 4
    }
41
42
    public static function create(): DenormalizerContextBuilderInterface
43
    {
44
        return new self();
45 4
    }
46
47 4
    public function setAllowedAdditionalFields(
48
        array $allowedAdditionalFields = null
49
    ): DenormalizerContextBuilderInterface {
50
        $this->allowedAdditionalFields = $allowedAdditionalFields;
51
52
        return $this;
53
    }
54
55 1
    /**
56
     * @deprecated
57
     *
58 1
     * @param string[] $groups
59
     */
60 1
    public function setGroups(array $groups): DenormalizerContextBuilderInterface
61
    {
62
        $this->groups = $groups;
0 ignored issues
show
Deprecated Code introduced by
The property Chubbyphp\Deserializatio...ContextBuilder::$groups has been deprecated. ( Ignorable by Annotation )

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

62
        /** @scrutinizer ignore-deprecated */ $this->groups = $groups;
Loading history...
63
64
        return $this;
65
    }
66
67
    public function setRequest(ServerRequestInterface $request = null): DenormalizerContextBuilderInterface
68
    {
69
        $this->request = $request;
70 1
71
        return $this;
72 1
    }
73
74 1
    /**
75
     * @deprecated
76
     */
77
    public function setResetMissingFields(bool $resetMissingFields): DenormalizerContextBuilderInterface
78
    {
79
        @trigger_error(
80
            'setResetMissingFields is broken by design, please do this your self by model or repository',
81
            E_USER_DEPRECATED
82 2
        );
83
84 2
        $this->resetMissingFields = $resetMissingFields;
85
86 2
        return $this;
87
    }
88
89
    public function setAttributes(array $attributes): DenormalizerContextBuilderInterface
90
    {
91
        $this->attributes = $attributes;
92
93
        return $this;
94
    }
95
96 1
    public function getContext(): DenormalizerContextInterface
97
    {
98 1
        return new DenormalizerContext(
99 1
            $this->allowedAdditionalFields,
100 1
            $this->groups,
0 ignored issues
show
Deprecated Code introduced by
The property Chubbyphp\Deserializatio...ContextBuilder::$groups has been deprecated. ( Ignorable by Annotation )

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

100
            /** @scrutinizer ignore-deprecated */ $this->groups,
Loading history...
101
            $this->request,
102
            $this->resetMissingFields,
103 1
            $this->attributes
104
        );
105 1
    }
106
}
107