Completed
Push — master ( 22512f...2e0539 )
by Kamil
24:53
created

AttributeValue::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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