Completed
Push — master ( 799d88...dee4c0 )
by Antoine
21s queued 13s
created

PropertyMetadata::getSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Metadata\Property;
15
16
use Symfony\Component\PropertyInfo\Type;
17
18
/**
19
 * Property metadata.
20
 *
21
 * @author Kévin Dunglas <[email protected]>
22
 */
23
final class PropertyMetadata
24
{
25
    private $type;
26
    private $description;
27
    private $readable;
28
    private $writable;
29
    private $readableLink;
30
    private $writableLink;
31
    private $required;
32
    private $iri;
33
    private $identifier;
34
    /**
35
     * @deprecated since 2.6, to be removed in 3.0
36
     */
37
    private $childInherited;
38
    private $attributes;
39
    private $subresource;
40
    private $initializable;
41
    /**
42
     * @var null
43
     */
44
    private $default;
45
    /**
46
     * @var null
47
     */
48
    private $example;
49
    private $schema;
50
51
    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, SubresourceMetadata $subresource = null, bool $initializable = null, $default = null, $example = null, array $schema = null)
52
    {
53
        $this->type = $type;
54
        $this->description = $description;
55
        $this->readable = $readable;
56
        $this->writable = $writable;
57
        $this->readableLink = $readableLink;
58
        $this->writableLink = $writableLink;
59
        $this->required = $required;
60
        $this->identifier = $identifier;
61
        $this->iri = $iri;
62
        if (null !== $childInherited) {
63
            @trigger_error(sprintf('Providing a non-null value for the 10th argument ($childInherited) of the "%s" constructor is deprecated since 2.6 and will not be supported in 3.0.', __CLASS__), E_USER_DEPRECATED);
64
        }
65
        $this->childInherited = $childInherited;
0 ignored issues
show
Deprecated Code introduced by
The property ApiPlatform\Core\Metadat...tadata::$childInherited has been deprecated: since 2.6, to be removed in 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
        /** @scrutinizer ignore-deprecated */ $this->childInherited = $childInherited;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
66
        $this->attributes = $attributes;
67
        $this->subresource = $subresource;
68
        $this->initializable = $initializable;
69
        $this->default = $default;
70
        $this->example = $example;
71
        $this->schema = $schema;
72
    }
73
74
    /**
75
     * Gets type.
76
     */
77
    public function getType(): ?Type
78
    {
79
        return $this->type;
80
    }
81
82
    /**
83
     * Returns a new instance with the given type.
84
     */
85
    public function withType(Type $type): self
86
    {
87
        $metadata = clone $this;
88
        $metadata->type = $type;
89
90
        return $metadata;
91
    }
92
93
    /**
94
     * Gets description.
95
     */
96
    public function getDescription(): ?string
97
    {
98
        return $this->description;
99
    }
100
101
    /**
102
     * Returns a new instance with the given description.
103
     */
104
    public function withDescription(string $description): self
105
    {
106
        $metadata = clone $this;
107
        $metadata->description = $description;
108
109
        return $metadata;
110
    }
111
112
    /**
113
     * Is readable?
114
     */
115
    public function isReadable(): ?bool
116
    {
117
        return $this->readable;
118
    }
119
120
    /**
121
     * Returns a new instance of Metadata with the given readable flag.
122
     */
123
    public function withReadable(bool $readable): self
124
    {
125
        $metadata = clone $this;
126
        $metadata->readable = $readable;
127
128
        return $metadata;
129
    }
130
131
    /**
132
     * Is writable?
133
     */
134
    public function isWritable(): ?bool
135
    {
136
        return $this->writable;
137
    }
138
139
    /**
140
     * Returns a new instance with the given writable flag.
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
    public function isRequired(): ?bool
154
    {
155
        if (true === $this->required && false === $this->writable) {
156
            return false;
157
        }
158
159
        return $this->required;
160
    }
161
162
    /**
163
     * Returns a new instance with the given required flag.
164
     */
165
    public function withRequired(bool $required): self
166
    {
167
        $metadata = clone $this;
168
        $metadata->required = $required;
169
170
        return $metadata;
171
    }
172
173
    /**
174
     * Should an IRI or an object be provided in write context?
175
     */
176
    public function isWritableLink(): ?bool
177
    {
178
        return $this->writableLink;
179
    }
180
181
    /**
182
     * Returns a new instance with the given writable link flag.
183
     */
184
    public function withWritableLink(bool $writableLink): self
185
    {
186
        $metadata = clone $this;
187
        $metadata->writableLink = $writableLink;
188
189
        return $metadata;
190
    }
191
192
    /**
193
     * Is an IRI or an object generated in read context?
194
     */
195
    public function isReadableLink(): ?bool
196
    {
197
        return $this->readableLink;
198
    }
199
200
    /**
201
     * Returns a new instance with the given readable link flag.
202
     */
203
    public function withReadableLink(bool $readableLink): self
204
    {
205
        $metadata = clone $this;
206
        $metadata->readableLink = $readableLink;
207
208
        return $metadata;
209
    }
210
211
    /**
212
     * Gets IRI of this property.
213
     */
214
    public function getIri(): ?string
215
    {
216
        return $this->iri;
217
    }
218
219
    /**
220
     * Returns a new instance with the given IRI.
221
     */
222
    public function withIri(string $iri = null): self
223
    {
224
        $metadata = clone $this;
225
        $metadata->iri = $iri;
226
227
        return $metadata;
228
    }
229
230
    /**
231
     * Is this attribute an identifier?
232
     */
233
    public function isIdentifier(): ?bool
234
    {
235
        return $this->identifier;
236
    }
237
238
    /**
239
     * Returns a new instance with the given identifier flag.
240
     */
241
    public function withIdentifier(bool $identifier): self
242
    {
243
        $metadata = clone $this;
244
        $metadata->identifier = $identifier;
245
246
        return $metadata;
247
    }
248
249
    /**
250
     * Gets attributes.
251
     */
252
    public function getAttributes(): ?array
253
    {
254
        return $this->attributes;
255
    }
256
257
    /**
258
     * Gets an attribute.
259
     *
260
     * @param mixed|null $defaultValue
261
     */
262
    public function getAttribute(string $key, $defaultValue = null)
263
    {
264
        return $this->attributes[$key] ?? $defaultValue;
265
    }
266
267
    /**
268
     * Returns a new instance with the given attribute.
269
     */
270
    public function withAttributes(array $attributes): self
271
    {
272
        $metadata = clone $this;
273
        $metadata->attributes = $attributes;
274
275
        return $metadata;
276
    }
277
278
    /**
279
     * @deprecated since 2.6, to be removed in 3.0
280
     */
281
    public function getChildInherited(): ?string
282
    {
283
        return $this->childInherited;
0 ignored issues
show
Deprecated Code introduced by
The property ApiPlatform\Core\Metadat...tadata::$childInherited has been deprecated: since 2.6, to be removed in 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

283
        return /** @scrutinizer ignore-deprecated */ $this->childInherited;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
284
    }
285
286
    /**
287
     * @deprecated since 2.6, to be removed in 3.0
288
     */
289
    public function hasChildInherited(): bool
290
    {
291
        return null !== $this->childInherited;
0 ignored issues
show
Deprecated Code introduced by
The property ApiPlatform\Core\Metadat...tadata::$childInherited has been deprecated: since 2.6, to be removed in 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

291
        return null !== /** @scrutinizer ignore-deprecated */ $this->childInherited;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
292
    }
293
294
    /**
295
     * @deprecated since 2.4, to be removed in 3.0
296
     */
297
    public function isChildInherited(): ?string
298
    {
299
        @trigger_error(sprintf('"%s::%s" is deprecated since 2.4 and will be removed in 3.0.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
300
301
        return $this->getChildInherited();
0 ignored issues
show
Deprecated Code introduced by
The function ApiPlatform\Core\Metadat...ta::getChildInherited() has been deprecated: since 2.6, to be removed in 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

301
        return /** @scrutinizer ignore-deprecated */ $this->getChildInherited();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
302
    }
303
304
    /**
305
     * @deprecated since 2.6, to be removed in 3.0
306
     */
307
    public function withChildInherited(string $childInherited): self
308
    {
309
        @trigger_error(sprintf('"%s::%s" is deprecated since 2.6 and will be removed in 3.0.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
310
311
        $metadata = clone $this;
312
        $metadata->childInherited = $childInherited;
0 ignored issues
show
Deprecated Code introduced by
The property ApiPlatform\Core\Metadat...tadata::$childInherited has been deprecated: since 2.6, to be removed in 3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

312
        /** @scrutinizer ignore-deprecated */ $metadata->childInherited = $childInherited;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
313
314
        return $metadata;
315
    }
316
317
    /**
318
     * Represents whether the property has a subresource.
319
     */
320
    public function hasSubresource(): bool
321
    {
322
        return null !== $this->subresource;
323
    }
324
325
    /**
326
     * Gets the subresource metadata.
327
     */
328
    public function getSubresource(): ?SubresourceMetadata
329
    {
330
        return $this->subresource;
331
    }
332
333
    /**
334
     * Returns a new instance with the given subresource.
335
     *
336
     * @param SubresourceMetadata $subresource
337
     */
338
    public function withSubresource(SubresourceMetadata $subresource = null): self
339
    {
340
        $metadata = clone $this;
341
        $metadata->subresource = $subresource;
342
343
        return $metadata;
344
    }
345
346
    /**
347
     * Is initializable?
348
     */
349
    public function isInitializable(): ?bool
350
    {
351
        return $this->initializable;
352
    }
353
354
    /**
355
     * Returns a new instance with the given initializable flag.
356
     */
357
    public function withInitializable(bool $initializable): self
358
    {
359
        $metadata = clone $this;
360
        $metadata->initializable = $initializable;
361
362
        return $metadata;
363
    }
364
365
    /**
366
     * Returns the default value of the property or NULL if the property doesn't have a default value.
367
     */
368
    public function getDefault()
369
    {
370
        return $this->default;
371
    }
372
373
    /**
374
     * Returns a new instance with the given default value for the property.
375
     */
376
    public function withDefault($default): self
377
    {
378
        $metadata = clone $this;
379
        $metadata->default = $default;
380
381
        return $metadata;
382
    }
383
384
    /**
385
     * Returns an example of the value of the property.
386
     */
387
    public function getExample()
388
    {
389
        return $this->example;
390
    }
391
392
    /**
393
     * Returns a new instance with the given example.
394
     */
395
    public function withExample($example): self
396
    {
397
        $metadata = clone $this;
398
        $metadata->example = $example;
399
400
        return $metadata;
401
    }
402
403
    /**
404
     * @return array
405
     */
406
    public function getSchema(): ?array
407
    {
408
        return $this->schema;
409
    }
410
411
    /**
412
     * Returns a new instance with the given schema.
413
     */
414
    public function withSchema(array $schema = null): self
415
    {
416
        $metadata = clone $this;
417
        $metadata->schema = $schema;
418
419
        return $metadata;
420
    }
421
}
422