Completed
Pull Request — master (#1225)
by Antoine
03:02
created

SubresourceMetadata::withResourceClass()   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
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Metadata\Property;
15
16
/**
17
 * Subresource metadata.
18
 *
19
 * @author Antoine Bluchet <[email protected]>
20
 */
21
final class SubresourceMetadata
22
{
23
    private $resourceClass;
24
    private $collection;
25
    private $property;
26
    private $parentResourceClass;
27
28
    public function __construct(string $resourceClass, bool $collection = false, string $property, string $parentResourceClass)
29
    {
30
        $this->resourceClass = $resourceClass;
31
        $this->collection = $collection;
32
        $this->property = $property;
33
        $this->parentResourceClass = $parentResourceClass;
34
    }
35
36
    public function getResourceClass(): string
37
    {
38
        return $this->resourceClass;
39
    }
40
41
    public function withResourceClass($resourceClass): self
42
    {
43
        $metadata = clone $this;
44
        $metadata->resourceClass = $resourceClass;
45
46
        return $metadata;
47
    }
48
49
    public function isCollection(): bool
50
    {
51
        return $this->collection;
52
    }
53
54
    public function withCollection(bool $collection): self
55
    {
56
        $metadata = clone $this;
57
        $metadata->collection = $collection;
58
59
        return $metadata;
60
    }
61
62
    public function withProperty(string $property): self
63
    {
64
        $metadata = clone $this;
65
        $metadata->property = $property;
66
67
        return $metadata;
68
    }
69
70
    public function getProperty(): string
71
    {
72
        return $this->property;
73
    }
74
75
    public function withParentResourceClass(string $parentResourceClass): self
76
    {
77
        $metadata = clone $this;
78
        $metadata->parentResourceClass = $parentResourceClass;
79
80
        return $metadata;
81
    }
82
83
    public function getParentResourceClass(): string
84
    {
85
        return $this->parentResourceClass;
86
    }
87
}
88