Completed
Push — develop ( e72854...0832ef )
by Daniel
06:46
created

Collection::setResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Entity\Component\Collection;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use Silverback\ApiComponentBundle\Entity\Component\AbstractComponent;
10
use Symfony\Component\Serializer\Annotation\Groups;
11
12
/**
13
 * @ORM\Entity()
14
 * @author Daniel West <[email protected]>
15
 */
16
class Collection extends AbstractComponent
17
{
18
    /**
19
     * @ORM\Column()
20
     * @Groups({"component", "content"})
21
     * @var string
22
     */
23
    private $resource;
24
25
    /**
26
     * @ORM\Column(type="integer", nullable=true)
27
     * @Groups({"component", "content"})
28
     * @var int|null
29
     */
30
    private $perPage;
31
32
    /**
33
     * @ORM\Column(nullable=true)
34
     * @Groups({"component", "content"})
35
     * @var string|null
36
     */
37
    private $title;
38
39
    /**
40
     * @var array|\Traversable
41
     * @Groups({"component_read", "content_read"})
42
     */
43
    private $collection;
44
45
    /**
46
     * @var ArrayCollection
47
     * @Groups({"component_read", "content_read"})
48
     */
49
    private $collectionRoutes;
50
51
    /**
52
     * Collection constructor.
53
     */
54
    public function __construct()
55
    {
56
        parent::__construct();
57
        $this->collectionRoutes = new ArrayCollection;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getResource(): string
64
    {
65
        return $this->resource;
66
    }
67
68
    /**
69
     * @param string $resource
70
     * @return Collection
71
     */
72
    public function setResource(string $resource): self
73
    {
74
        $this->resource = $resource;
75
        return $this;
76
    }
77
78
    /**
79
     * @return null|int
80
     */
81
    public function getPerPage(): ?int
82
    {
83
        return $this->perPage;
84
    }
85
86
    /**
87
     * @param null|int $perPage
88
     * @return Collection
89
     */
90
    public function setPerPage(?int $perPage): self
91
    {
92
        $this->perPage = $perPage;
93
        return $this;
94
    }
95
96
    /**
97
     * @return null|string
98
     */
99
    public function getTitle(): ?string
100
    {
101
        return $this->title;
102
    }
103
104
    /**
105
     * @param null|string $title
106
     * @return Collection
107
     */
108
    public function setTitle(?string $title): self
109
    {
110
        $this->title = $title;
111
        return $this;
112
    }
113
114
    /**
115
     * @return array|\Traversable
116
     */
117
    public function getCollection()
118
    {
119
        return $this->collection;
120
    }
121
122
    /**
123
     * @param array|\Traversable $collection
124
     * @return Collection
125
     */
126
    public function setCollection($collection): self
127
    {
128
        $this->collection = $collection;
129
        return $this;
130
    }
131
132
    /**
133
     * @return ArrayCollection|null
134
     */
135
    public function getCollectionRoutes(): ArrayCollection
136
    {
137
        return $this->collectionRoutes;
138
    }
139
140
    /**
141
     * @param string $method
142
     * @param string $route
143
     * @return static
144
     */
145
    public function addCollectionRoute(string $method, string $route)
146
    {
147
        if (!$this->collectionRoutes) {
148
            $this->collectionRoutes = new ArrayCollection;
149
        }
150
        $this->collectionRoutes->set($method, $route);
151
        return $this;
152
    }
153
}
154