Completed
Push — master ( 0891d0...500833 )
by Paweł
48:22 queued 28:23
created

AttributeValue::setLocaleCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Component\Attribute\Model;
13
14
use Webmozart\Assert\Assert;
15
16
/**
17
 * @author Paweł Jędrzejewski <[email protected]>
18
 * @author Mateusz Zalewski <[email protected]>
19
 */
20
class AttributeValue implements AttributeValueInterface
21
{
22
    /**
23
     * @var mixed
24
     */
25
    protected $id;
26
27
    /**
28
     * @var AttributeSubjectInterface
29
     */
30
    protected $subject;
31
32
    /**
33
     * @var AttributeInterface
34
     */
35
    protected $attribute;
36
37
    /**
38
     * @var string
39
     */
40
    protected $localeCode;
41
42
    /**
43
     * @var string
44
     */
45
    private $text;
46
47
    /**
48
     * @var bool
49
     */
50
    private $boolean;
51
52
    /**
53
     * @var int
54
     */
55
    private $integer;
56
57
    /**
58
     * @var float
59
     */
60
    private $float;
61
62
    /**
63
     * @var \DateTime
64
     */
65
    private $datetime;
66
67
    /**
68
     * @var \DateTime
69
     */
70
    private $date;
71
72
    /**
73
     * @var array
74
     */
75
    private $json;
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getId()
81
    {
82
        return $this->id;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function getSubject()
89
    {
90
        return $this->subject;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function setSubject(AttributeSubjectInterface $subject = null)
97
    {
98
        $this->subject = $subject;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function getAttribute()
105
    {
106
        return $this->attribute;
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function setAttribute(AttributeInterface $attribute)
113
    {
114
        $this->attribute = $attribute;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function getLocaleCode()
121
    {
122
        return $this->localeCode;
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function setLocaleCode($localeCode)
129
    {
130
        Assert::string($localeCode);
131
132
        $this->localeCode = $localeCode;
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138
    public function getValue()
139
    {
140
        if (null === $this->attribute) {
141
            return null;
142
        }
143
144
        $getter = 'get' . $this->attribute->getStorageType();
145
146
        return $this->$getter();
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function setValue($value)
153
    {
154
        $this->assertAttributeIsSet();
155
156
        $setter = 'set' . $this->attribute->getStorageType();
157
158
        $this->$setter($value);
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164
    public function getCode()
165
    {
166
        $this->assertAttributeIsSet();
167
168
        return $this->attribute->getCode();
169
    }
170
171
    /**
172
     * {@inheritdoc}
173
     */
174
    public function getName()
175
    {
176
        $this->assertAttributeIsSet();
177
178
        return $this->attribute->getName();
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public function getType()
185
    {
186
        $this->assertAttributeIsSet();
187
188
        return $this->attribute->getType();
189
    }
190
191
    /**
192
     * @return bool
193
     */
194
    protected function getBoolean()
195
    {
196
        return $this->boolean;
197
    }
198
199
    /**
200
     * @param bool $boolean
201
     */
202
    protected function setBoolean($boolean)
203
    {
204
        $this->boolean = $boolean;
205
    }
206
207
    /**
208
     * @return string
209
     */
210
    protected function getText()
211
    {
212
        return $this->text;
213
    }
214
215
    /**
216
     * @param string $text
217
     */
218
    protected function setText($text)
219
    {
220
        $this->text = $text;
221
    }
222
223
    /**
224
     * @return int
225
     */
226
    protected function getInteger()
227
    {
228
        return $this->integer;
229
    }
230
231
    /**
232
     * @param int $integer
233
     */
234
    protected function setInteger($integer)
235
    {
236
        $this->integer = $integer;
237
    }
238
239
    /**
240
     * @return float
241
     */
242
    protected function getFloat()
243
    {
244
        return $this->float;
245
    }
246
247
    /**
248
     * @param float $float
249
     */
250
    protected function setFloat($float)
251
    {
252
        $this->float = $float;
253
    }
254
255
    /**
256
     * @return \DateTime
257
     */
258
    protected function getDatetime()
259
    {
260
        return $this->datetime;
261
    }
262
263
    /**
264
     * @param \DateTime $datetime
265
     */
266
    protected function setDatetime(\DateTime $datetime)
267
    {
268
        $this->datetime = $datetime;
269
    }
270
271
    /**
272
     * @return \DateTime
273
     */
274
    protected function getDate()
275
    {
276
        return $this->date;
277
    }
278
279
    /**
280
     * @param \DateTime $date
281
     */
282
    protected function setDate(\DateTime $date)
283
    {
284
        $this->date = $date;
285
    }
286
287
    /**
288
     * @return array
289
     */
290
    public function getJson()
291
    {
292
        return $this->json;
293
    }
294
295
    /**
296
     * @param array $json
297
     */
298
    public function setJson(array $json)
299
    {
300
        $this->json = $json;
301
    }
302
303
    /**
304
     * @throws \BadMethodCallException
305
     */
306
    protected function assertAttributeIsSet()
307
    {
308
        if (null === $this->attribute) {
309
            throw new \BadMethodCallException('The attribute is undefined, so you cannot access proxy methods.');
310
        }
311
    }
312
}
313