Issues (17)

src/Denormalizer/DenormalizerContext.php (2 issues)

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 DenormalizerContext implements DenormalizerContextInterface
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;
32
33
    /**
34
     * @var array
35
     */
36
    private $attributes;
37
38
    /**
39
     * @param string[] $groups
40
     */
41
    public function __construct(
42
        array $allowedAdditionalFields = null,
43
        array $groups = [],
44
        ServerRequestInterface $request = null,
45 4
        bool $resetMissingFields = false,
46
        array $attributes = []
47
    ) {
48
        $this->allowedAdditionalFields = $allowedAdditionalFields;
49
        $this->groups = $groups;
0 ignored issues
show
Deprecated Code introduced by
The property Chubbyphp\Deserializatio...malizerContext::$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

49
        /** @scrutinizer ignore-deprecated */ $this->groups = $groups;
Loading history...
50
        $this->request = $request;
51
52 4
        if ($resetMissingFields) {
53 4
            @trigger_error(
54 4
                'resetMissingFields is broken by design, please do this your self by model or repository',
55
                E_USER_DEPRECATED
56 4
            );
57 1
        }
58 1
59 1
        $this->resetMissingFields = $resetMissingFields;
60
        $this->attributes = $attributes;
61
    }
62
63 4
    /**
64 4
     * @return array|null
65 4
     */
66
    public function getAllowedAdditionalFields()
67
    {
68
        return $this->allowedAdditionalFields;
69
    }
70 2
71
    /**
72 2
     * @deprecated
73
     *
74
     * @return string[]
75
     */
76
    public function getGroups(): array
77
    {
78
        return $this->groups;
0 ignored issues
show
Deprecated Code introduced by
The property Chubbyphp\Deserializatio...malizerContext::$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

78
        return /** @scrutinizer ignore-deprecated */ $this->groups;
Loading history...
79
    }
80 2
81
    /**
82 2
     * @return ServerRequestInterface|null
83
     */
84
    public function getRequest()
85
    {
86
        return $this->request;
87
    }
88 2
89
    /**
90 2
     * @deprecated
91
     */
92
    public function isResetMissingFields(): bool
93
    {
94
        return $this->resetMissingFields;
95
    }
96
97
    public function getAttributes(): array
98 3
    {
99
        return $this->attributes;
100 3
    }
101
102
    /**
103
     * @param mixed $default
104
     *
105
     * @return mixed
106 3
     */
107
    public function getAttribute(string $name, $default = null)
108 3
    {
109
        if (isset($this->attributes[$name])) {
110
            return $this->attributes[$name];
111
        }
112
113
        return $default;
114
    }
115
116
    /**
117 2
     * @param mixed $value
118
     */
119 2
    public function withAttribute(string $name, $value): DenormalizerContextInterface
120 1
    {
121
        $context = clone $this;
122
        $context->attributes[$name] = $value;
123 1
124
        return $context;
125
    }
126
}
127