Completed
Pull Request — 2.1 (#1512)
by Antoine
02:49
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 $maxDepth;
26
27
    public function __construct(string $resourceClass, bool $collection = false, int $maxDepth = null)
28
    {
29
        $this->resourceClass = $resourceClass;
30
        $this->collection = $collection;
31
        $this->maxDepth = $maxDepth;
32
    }
33
34
    public function getResourceClass(): string
35
    {
36
        return $this->resourceClass;
37
    }
38
39
    public function withResourceClass($resourceClass): self
40
    {
41
        $metadata = clone $this;
42
        $metadata->resourceClass = $resourceClass;
43
44
        return $metadata;
45
    }
46
47
    public function isCollection(): bool
48
    {
49
        return $this->collection;
50
    }
51
52
    public function withCollection(bool $collection): self
53
    {
54
        $metadata = clone $this;
55
        $metadata->collection = $collection;
56
57
        return $metadata;
58
    }
59
60
    /**
61
     * @return int
62
     */
63
    public function getMaxDepth()
64
    {
65
        return $this->maxDepth;
66
    }
67
}
68