Completed
Push — master ( 107a7d...7905cb )
by Davis
01:23
created

Post::setAuthorId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: davis
5
 * Date: 7/23/17
6
 * Time: 3:04 AM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Entity;
10
11
12
use DateTime;
13
use Ramsey\Uuid\UuidInterface;
14
use stdClass;
15
16
/**
17
 * Class Post
18
 * @package DavisPeixoto\Entity
19
 */
20
class Post extends stdClass
21
{
22
    /**
23
     * @var UuidInterface
24
     */
25
    private $postId;
26
27
    /**
28
     * @var string $title
29
     */
30
    private $title;
31
32
    /**
33
     * @var string $body
34
     */
35
    private $body;
36
37
    /**
38
     * @var DateTime
39
     */
40
    private $publishDate;
41
42
    /**
43
     * @var Author
44
     */
45
    private $authorId;
46
47
    /**
48
     * @var Tag[]
49
     */
50
    private $tags;
51
52
    /**
53
     * Post constructor.
54
     * @param UuidInterface $postId
55
     * @param string $title
56
     * @param string $body
57
     * @param DateTime $publishDate
58
     * @param Author $authorId
59
     * @param Tag[]|null $tags
60
     */
61
    public function __construct(UuidInterface $postId, $title, $body, DateTime $publishDate, Author $authorId, array $tags = [])
62
    {
63
        $this->postId = $postId;
64
        $this->title = $title;
65
        $this->body = $body;
66
        $this->publishDate = $publishDate;
67
        $this->authorId = $authorId;
68
        $this->tags = $tags;
69
    }
70
71
    /**
72
     * @codeCoverageIgnore
73
     * @return UuidInterface
74
     */
75
    public function getPostId(): UuidInterface
76
    {
77
        return $this->postId;
78
    }
79
80
    /**
81
     * @codeCoverageIgnore
82
     * @param UuidInterface $postId
83
     */
84
    public function setPostId(UuidInterface $postId)
85
    {
86
        $this->postId = $postId;
87
    }
88
89
    /**
90
     * @codeCoverageIgnore
91
     * @return string
92
     */
93
    public function getTitle(): string
94
    {
95
        return $this->title;
96
    }
97
98
    /**
99
     * @codeCoverageIgnore
100
     * @param string $title
101
     */
102
    public function setTitle(string $title)
103
    {
104
        $this->title = $title;
105
    }
106
107
    /**
108
     * @codeCoverageIgnore
109
     * @return string
110
     */
111
    public function getBody(): string
112
    {
113
        return $this->body;
114
    }
115
116
    /**
117
     * @codeCoverageIgnore
118
     * @param string $body
119
     */
120
    public function setBody(string $body)
121
    {
122
        $this->body = $body;
123
    }
124
125
    /**
126
     * @codeCoverageIgnore
127
     * @return DateTime
128
     */
129
    public function getPublishDate(): DateTime
130
    {
131
        return $this->publishDate;
132
    }
133
134
    /**
135
     * @codeCoverageIgnore
136
     * @param DateTime $publishDate
137
     */
138
    public function setPublishDate(DateTime $publishDate)
139
    {
140
        $this->publishDate = $publishDate;
141
    }
142
143
    /**
144
     * @codeCoverageIgnore
145
     * @return Author
146
     */
147
    public function getAuthorId(): Author
148
    {
149
        return $this->authorId;
150
    }
151
152
    /**
153
     * @codeCoverageIgnore
154
     * @param Author $authorId
155
     */
156
    public function setAuthorId(Author $authorId)
157
    {
158
        $this->authorId = $authorId;
159
    }
160
161
    /**
162
     * @codeCoverageIgnore
163
     * @return Tag[]
164
     */
165
    public function getTags(): array
166
    {
167
        return $this->tags;
168
    }
169
170
    /**
171
     * @codeCoverageIgnore
172
     * @param Tag[] $tags
173
     */
174
    public function setTags(array $tags)
175
    {
176
        $this->tags = array_unique($tags);
177
    }
178
179
    public function addTag(Tag $tag)
180
    {
181
        $tags = $this->tags;
182
        $tags[] = $tag;
183
        $this->setTags($tags);
184
185
        return $this;
186
    }
187
188
    public function removeTag(Tag $tag)
189
    {
190
        foreach ($this->getTags() as $key => $value) {
191
            if ($value->getTagId() === $tag->getTagId()) {
192
                unset($this->tags[$key]);
193
194
                return $this;
195
            }
196
        }
197
198
        return $this;
199
    }
200
}
201