Passed
Pull Request — master (#57)
by Daniel
16:36 queued 11:06
created

Collection   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 14
eloc 28
c 3
b 0
f 0
dl 0
loc 101
ccs 0
cts 32
cp 0
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setResourceClass() 0 5 1
A addEndpoint() 0 8 2
A getEndpoints() 0 3 1
A setCollection() 0 8 3
A setEndpoints() 0 5 1
A getPerPage() 0 3 1
A setPerPage() 0 5 1
A getCollection() 0 3 1
A setDefaultQueryParameters() 0 5 1
A getDefaultQueryParameters() 0 3 1
A getResourceClass() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[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 Silverback\ApiComponentsBundle\Entity\Component;
15
16
use ApiPlatform\Core\Annotation\ApiProperty;
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\ORM\Mapping as ORM;
19
use Silverback\ApiComponentsBundle\Annotation as Silverback;
20
use Silverback\ApiComponentsBundle\Entity\Core\AbstractComponent;
21
use Silverback\ApiComponentsBundle\Entity\Utility\TimestampedTrait;
22
use Symfony\Component\Validator\Constraints as Assert;
23
use Traversable;
24
25
/**
26
 * @author Daniel West <[email protected]>
27
 *
28
 * @Silverback\Timestamped
29
 * @ORM\Entity
30
 */
31
class Collection extends AbstractComponent
32
{
33
    use TimestampedTrait;
34
35
    /**
36
     * @ORM\Column(nullable=false)
37
     * @Assert\NotNull(message="The resource class for a collection component is required")
38
     */
39
    private string $resourceClass;
40
41
    /**
42
     * @ORM\Column(type="integer", nullable=true)
43
     */
44
    private ?int $perPage;
45
46
    /**
47
     * @ORM\Column(type="json", nullable=true)
48
     */
49
    private ?array $defaultQueryParameters;
50
51
    /**
52
     * @ApiProperty(writable=false)
53
     */
54
    private array $collection = [];
55
56
    /**
57
     * @ApiProperty(writable=false)
58
     */
59
    private ?ArrayCollection $endpoints = null;
60
61
    public function getResourceClass(): string
62
    {
63
        return $this->resourceClass;
64
    }
65
66
    public function setResourceClass(string $resourceClass): self
67
    {
68
        $this->resourceClass = $resourceClass;
69
70
        return $this;
71
    }
72
73
    public function getPerPage(): ?int
74
    {
75
        return $this->perPage;
76
    }
77
78
    public function setPerPage(?int $perPage): self
79
    {
80
        $this->perPage = $perPage;
81
82
        return $this;
83
    }
84
85
    public function getDefaultQueryParameters(): ?array
86
    {
87
        return $this->defaultQueryParameters;
88
    }
89
90
    public function setDefaultQueryParameters(?array $defaultQueryParameters): self
91
    {
92
        $this->defaultQueryParameters = $defaultQueryParameters;
93
94
        return $this;
95
    }
96
97
    public function getCollection()
98
    {
99
        return $this->collection;
100
    }
101
102
    public function setCollection($collection): self
103
    {
104
        if (!$collection instanceof Traversable && !\is_array($collection)) {
105
            return $this;
106
        }
107
        $this->collection = $collection;
108
109
        return $this;
110
    }
111
112
    public function getEndpoints(): ?ArrayCollection
113
    {
114
        return $this->endpoints;
115
    }
116
117
    public function setEndpoints(ArrayCollection $endpoints): self
118
    {
119
        $this->endpoints = $endpoints;
120
121
        return $this;
122
    }
123
124
    public function addEndpoint(string $method, string $route): self
125
    {
126
        if (!$this->endpoints) {
127
            $this->endpoints = new ArrayCollection();
128
        }
129
        $this->endpoints->set($method, $route);
130
131
        return $this;
132
    }
133
}
134