Completed
Pull Request — master (#688)
by Antoine
03:43
created

PropertyMetadata::withDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
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 ApiPlatform\Core\Metadata\Property;
13
14
use Symfony\Component\PropertyInfo\Type;
15
16
/**
17
 * Property metadata.
18
 *
19
 * @author Kévin Dunglas <[email protected]>
20
 */
21
final class PropertyMetadata
22
{
23
    private $type;
24
    private $description;
25
    private $readable;
26
    private $writable;
27
    private $readableLink;
28
    private $writableLink;
29
    private $required;
30
    private $iri;
31
    private $identifier;
32
    private $childInherited;
33
    private $attributes;
34
35
    public function __construct(Type $type = null, string $description = null, bool $readable = null, bool $writable = null, bool $readableLink = null, bool $writableLink = null, bool $required = null, bool $identifier = null, string $iri = null, $childInherited = null, array $attributes = null)
36
    {
37
        $this->type = $type;
38
        $this->description = $description;
39
        $this->readable = $readable;
40
        $this->writable = $writable;
41
        $this->readableLink = $readableLink;
42
        $this->writableLink = $writableLink;
43
        $this->required = $required;
44
        $this->identifier = $identifier;
45
        $this->iri = $iri;
46
        $this->childInherited = $childInherited;
47
        $this->attributes = $attributes;
48
    }
49
50
    /**
51
     * Gets type.
52
     *
53
     * @return Type|null
54
     */
55
    public function getType()
56
    {
57
        return $this->type;
58
    }
59
60
    /**
61
     * Returns a new instance with the given type.
62
     *
63
     * @param Type $type
64
     *
65
     * @return self
66
     */
67
    public function withType(Type $type) : self
68
    {
69
        $metadata = clone $this;
70
        $metadata->type = $type;
71
72
        return $metadata;
73
    }
74
75
    /**
76
     * Gets description.
77
     *
78
     * @return string|null
79
     */
80
    public function getDescription()
81
    {
82
        return $this->description;
83
    }
84
85
    /**
86
     * Returns a new instance with the given description.
87
     *
88
     * @param string $description
89
     *
90
     * @return self
91
     */
92
    public function withDescription($description) : self
93
    {
94
        $metadata = clone $this;
95
        $metadata->description = $description;
96
97
        return $metadata;
98
    }
99
100
    /**
101
     * Is readable?
102
     *
103
     * @return bool|null
104
     */
105
    public function isReadable()
106
    {
107
        return $this->readable;
108
    }
109
110
    /**
111
     * Returns a new instance of Metadata with the given readable flag.
112
     *
113
     * @param bool $readable
114
     *
115
     * @return self
116
     */
117
    public function withReadable(bool $readable) : self
118
    {
119
        $metadata = clone $this;
120
        $metadata->readable = $readable;
121
122
        return $metadata;
123
    }
124
125
    /**
126
     * Is writable?
127
     *
128
     * @return bool|null
129
     */
130
    public function isWritable()
131
    {
132
        return $this->writable;
133
    }
134
135
    /**
136
     * Returns a new instance with the given writable flag.
137
     *
138
     * @param bool $writable
139
     *
140
     * @return self
141
     */
142
    public function withWritable(bool $writable) : self
143
    {
144
        $metadata = clone $this;
145
        $metadata->writable = $writable;
146
147
        return $metadata;
148
    }
149
150
    /**
151
     * Is required?
152
     *
153
     * @return bool|null
154
     */
155
    public function isRequired()
156
    {
157
        return $this->required;
158
    }
159
160
    /**
161
     * Returns a new instance with the given required flag.
162
     *
163
     * @param bool $required
164
     *
165
     * @return self
166
     */
167
    public function withRequired(bool $required) : self
168
    {
169
        $metadata = clone $this;
170
        $metadata->required = $required;
171
172
        return $metadata;
173
    }
174
175
    /**
176
     * Should an IRI or an object be provided in write context?
177
     *
178
     * @return bool|null
179
     */
180
    public function isWritableLink()
181
    {
182
        return $this->writableLink;
183
    }
184
185
    /**
186
     * Returns a new instance with the given writable link flag.
187
     *
188
     * @param bool $writableLink
189
     *
190
     * @return self
191
     */
192
    public function withWritableLink(bool $writableLink) : self
193
    {
194
        $metadata = clone $this;
195
        $metadata->writableLink = $writableLink;
196
197
        return $metadata;
198
    }
199
200
    /**
201
     * Is an IRI or an object generated in read context?
202
     *
203
     * @return bool|null
204
     */
205
    public function isReadableLink()
206
    {
207
        return $this->readableLink;
208
    }
209
210
    /**
211
     * Returns a new instance with the given readable link flag.
212
     *
213
     * @param bool $readableLink
214
     *
215
     * @return self
216
     */
217
    public function withReadableLink(bool $readableLink) : self
218
    {
219
        $metadata = clone $this;
220
        $metadata->readableLink = $readableLink;
221
222
        return $metadata;
223
    }
224
225
    /**
226
     * Gets IRI of this property.
227
     *
228
     * @return string|null
229
     */
230
    public function getIri()
231
    {
232
        return $this->iri;
233
    }
234
235
    /**
236
     * Returns a new instance with the given IRI.
237
     *
238
     * @param string|null $iri
239
     *
240
     * @return self
241
     */
242
    public function withIri(string $iri = null) : self
243
    {
244
        $metadata = clone $this;
245
        $metadata->iri = $iri;
246
247
        return $metadata;
248
    }
249
250
    /**
251
     * Is this attribute an identifier?
252
     *
253
     * @return bool|null
254
     */
255
    public function isIdentifier()
256
    {
257
        return $this->identifier;
258
    }
259
260
    /**
261
     * Returns a new instance with the given identifier flag.
262
     *
263
     * @param bool $identifier
264
     *
265
     * @return self
266
     */
267
    public function withIdentifier(bool $identifier) : self
268
    {
269
        $metadata = clone $this;
270
        $metadata->identifier = $identifier;
271
272
        return $metadata;
273
    }
274
275
    /**
276
     * Gets attributes.
277
     *
278
     * @return array|null
279
     */
280
    public function getAttributes()
281
    {
282
        return $this->attributes;
283
    }
284
285
    /**
286
     * Returns a new instance with the given attribute.
287
     *
288
     * @param array $attributes
289
     *
290
     * @return self
291
     */
292
    public function withAttributes(array $attributes) : self
293
    {
294
        $metadata = clone $this;
295
        $metadata->attributes = $attributes;
296
297
        return $metadata;
298
    }
299
300
    /**
301
     * Is the property inherited from a child class?
302
     *
303
     * @return string|null
304
     */
305
    public function isChildInherited()
306
    {
307
        return $this->childInherited;
308
    }
309
310
    /**
311
     * Returns a new instance with the given child inherited class.
312
     *
313
     * @param string $childInherited
314
     *
315
     * @return self
316
     */
317
    public function withChildInherited(string $childInherited) : self
318
    {
319
        $metadata = clone $this;
320
        $metadata->childInherited = $childInherited;
321
322
        return $metadata;
323
    }
324
}
325