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

Trail   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
dl 0
loc 137
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setPosts() 0 3 1
A __construct() 0 6 1
A setTrailId() 0 3 1
A getPosts() 0 3 1
A getTrailId() 0 3 1
A getDescription() 0 3 1
A setName() 0 3 1
A addPost() 0 7 1
A removePost() 0 11 3
A setDescription() 0 3 1
A getName() 0 3 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 Ramsey\Uuid\UuidInterface;
13
use stdClass;
14
15
/**
16
 * Class Trail
17
 * @package DavisPeixoto\Entity
18
 */
19
class Trail extends stdClass
20
{
21
    /**
22
     * @var UuidInterface
23
     */
24
    private $trailId;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var string
33
     */
34
    private $description;
35
36
    /**
37
     * @var array|Post[]
38
     */
39
    private $posts;
40
41
    /**
42
     * Trail constructor.
43
     * @param UuidInterface $trailId
44
     * @param string $name
45
     * @param string $description
46
     * @param Post[] $posts
47
     */
48
    public function __construct(UuidInterface $trailId, $name, $description, array $posts = [])
49
    {
50
        $this->trailId = $trailId;
51
        $this->name = $name;
52
        $this->description = $description;
53
        $this->posts = $posts;
54
    }
55
56
    /**
57
     * @codeCoverageIgnore
58
     * @return UuidInterface
59
     */
60
    public function getTrailId(): UuidInterface
61
    {
62
        return $this->trailId;
63
    }
64
65
    /**
66
     * @codeCoverageIgnore
67
     * @param UuidInterface $trailId
68
     */
69
    public function setTrailId(UuidInterface $trailId)
70
    {
71
        $this->trailId = $trailId;
72
    }
73
74
    /**
75
     * @codeCoverageIgnore
76
     * @return string
77
     */
78
    public function getName(): string
79
    {
80
        return $this->name;
81
    }
82
83
    /**
84
     * @codeCoverageIgnore
85
     * @param string $name
86
     */
87
    public function setName(string $name)
88
    {
89
        $this->name = $name;
90
    }
91
92
    /**
93
     * @codeCoverageIgnore
94
     * @return string
95
     */
96
    public function getDescription(): string
97
    {
98
        return $this->description;
99
    }
100
101
    /**
102
     * @codeCoverageIgnore
103
     * @param string $description
104
     */
105
    public function setDescription(string $description)
106
    {
107
        $this->description = $description;
108
    }
109
110
    /**
111
     * @codeCoverageIgnore
112
     * @return Post[]
113
     */
114
    public function getPosts(): array
115
    {
116
        return $this->posts;
117
    }
118
119
    /**
120
     * @codeCoverageIgnore
121
     * @param Post[] $posts
122
     */
123
    public function setPosts($posts)
124
    {
125
        $this->posts = array_unique($posts);
126
    }
127
128
    /**
129
     * @param Post $post
130
     * @return $this
131
     */
132
    public function addPost(Post $post)
133
    {
134
        $posts = $this->getPosts();
135
        $posts[] = $post;
136
        $this->setPosts($posts);
137
138
        return $this;
139
    }
140
141
    /**
142
     * @param Post $post
143
     * @return $this
144
     */
145
    public function removePost(Post $post)
146
    {
147
        foreach ($this->getPosts() as $key => $value) {
148
            if ($value->getPostId() === $post->getPostId()) {
149
                unset($this->posts[$key]);
150
151
                return $this;
152
            }
153
        }
154
155
        return $this;
156
    }
157
}
158