Completed
Push — master ( 1319dc...6e6413 )
by Lukas Kahwe
05:12
created

Context::setSerializeNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Context;
13
14
/**
15
 * Stores the serialization or deserialization context (groups, version, ...).
16
 *
17
 * @author Ener-Getick <[email protected]>
18
 */
19
final class Context
20
{
21
    /**
22
     * @var array
23
     */
24
    private $attributes = array();
25
    /**
26
     * @var int|null
27
     */
28
    private $version;
29
    /**
30
     * @var array
31
     */
32
    private $groups = array();
33
    /**
34
     * @var int
35
     */
36
    private $maxDepth;
37
    /**
38
     * @var bool
39
     */
40
    private $serializeNull;
41
42
    /**
43
     * Sets an attribute.
44
     *
45
     * @param string $key
46
     * @param mixed  $value
47
     *
48
     * @return self
49
     */
50 2
    public function setAttribute($key, $value)
51
    {
52 2
        $this->attributes[$key] = $value;
53
54 2
        return $this;
55
    }
56
57
    /**
58
     * Checks if contains a normalization attribute.
59
     *
60
     * @param string $key
61
     *
62
     * @return bool
63
     */
64 1
    public function hasAttribute($key)
65
    {
66 1
        return isset($this->attributes[$key]);
67
    }
68
69
    /**
70
     * Gets an attribute.
71
     *
72
     * @param string $key
73
     *
74
     * @return mixed
75
     */
76 1
    public function getAttribute($key)
77
    {
78 1
        if (isset($this->attributes[$key])) {
79 1
            return $this->attributes[$key];
80
        }
81
    }
82
83
    /**
84
     * Gets the attributes.
85
     *
86
     * @return array
87
     */
88 14
    public function getAttributes()
89
    {
90 14
        return $this->attributes;
91
    }
92
93
    /**
94
     * Sets the normalization version.
95
     *
96
     * @param int|null $version
97
     *
98
     * @return self
99
     */
100 6
    public function setVersion($version)
101
    {
102 6
        $this->version = $version;
103
104 6
        return $this;
105
    }
106
107
    /**
108
     * Gets the normalization version.
109
     *
110
     * @return int|null
111
     */
112 29
    public function getVersion()
113
    {
114 29
        return $this->version;
115
    }
116
117
    /**
118
     * Adds a normalization group.
119
     *
120
     * @param string $group
121
     *
122
     * @return self
123
     */
124 6
    public function addGroup($group)
125
    {
126 6
        if (!in_array($group, $this->groups)) {
127 6
            $this->groups[] = $group;
128 6
        }
129
130 6
        return $this;
131
    }
132
133
    /**
134
     * Adds normalization groups.
135
     *
136
     * @param string[] $groups
137
     *
138
     * @return self
139
     */
140 5
    public function addGroups(array $groups)
141
    {
142 5
        foreach ($groups as $group) {
143 5
            $this->addGroup($group);
144 5
        }
145
146 5
        return $this;
147
    }
148
149
    /**
150
     * Gets the normalization groups.
151
     *
152
     * @return array
153
     */
154 31
    public function getGroups()
155
    {
156 31
        return $this->groups;
157
    }
158
159
    /**
160
     * Sets the normalization max depth.
161
     *
162
     * @param int|null $depth
0 ignored issues
show
Bug introduced by
There is no parameter named $depth. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
163
     *
164
     * @return self
165
     */
166 3
    public function setMaxDepth($maxDepth)
167
    {
168 3
        $this->maxDepth = $maxDepth;
169
170 3
        return $this;
171
    }
172
173
    /**
174
     * Gets the normalization max depth.
175
     *
176
     * @return int|null
177
     */
178 15
    public function getMaxDepth()
179
    {
180 15
        return $this->maxDepth;
181
    }
182
183
    /**
184
     * Sets serialize null.
185
     *
186
     * @param bool|null $serializeNull
187
     *
188
     * @return self
189
     */
190 16
    public function setSerializeNull($serializeNull)
191
    {
192 16
        $this->serializeNull = $serializeNull;
193
194 16
        return $this;
195
    }
196
197
    /**
198
     * Gets serialize null.
199
     *
200
     * @return bool|null
201
     */
202 28
    public function getSerializeNull()
203
    {
204 28
        return $this->serializeNull;
205
    }
206
}
207