Completed
Push — master ( a422c7...41ba82 )
by Guilh
09:24
created

Context::setGroups()   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 1
Metric Value
c 1
b 0
f 1
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 28
    public function setAttribute($key, $value)
51
    {
52 28
        $this->attributes[$key] = $value;
53
54 28
        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 2
    public function getAttribute($key)
77
    {
78 2
        if (isset($this->attributes[$key])) {
79 2
            return $this->attributes[$key];
80
        }
81
    }
82
83
    /**
84
     * Gets the attributes.
85
     *
86
     * @return array
87
     */
88 17
    public function getAttributes()
89
    {
90 17
        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 32
    public function getVersion()
113
    {
114 32
        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 34
    public function getGroups()
155
    {
156 34
        return $this->groups;
157
    }
158
159
    /**
160
     * Set the normalization groups.
161
     *
162
     * @param array $groups
163
     *
164
     * @return self
165
     */
166 2
    public function setGroups(array $groups)
167
    {
168 2
        $this->groups = $groups;
169
170 2
        return $this;
171
    }
172
173
    /**
174
     * Sets the normalization max depth.
175
     *
176
     * @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...
177
     *
178 18
     * @return self
179
     */
180 18
    public function setMaxDepth($maxDepth)
181
    {
182
        $this->maxDepth = $maxDepth;
183
184
        return $this;
185
    }
186
187
    /**
188
     * Gets the normalization max depth.
189
     *
190 18
     * @return int|null
191
     */
192 18
    public function getMaxDepth()
193
    {
194 18
        return $this->maxDepth;
195
    }
196
197
    /**
198
     * Sets serialize null.
199
     *
200
     * @param bool|null $serializeNull
201
     *
202 30
     * @return self
203
     */
204 30
    public function setSerializeNull($serializeNull)
205
    {
206
        $this->serializeNull = $serializeNull;
207
208
        return $this;
209
    }
210
211
    /**
212
     * Gets serialize null.
213
     *
214
     * @return bool|null
215
     */
216
    public function getSerializeNull()
217
    {
218
        return $this->serializeNull;
219
    }
220
}
221