Completed
Push — master ( 12d04d...f0be6a )
by Albert
02:59
created

Post::addTag()   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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Albert221\Blog\Entity;
4
5
use DateTime;
6
use Doctrine\Common\Collections\ArrayCollection;
7
8
/**
9
 * @Entity(repositoryClass="\Albert221\Blog\Repository\Database\PostRepository") @Table(name="posts")
10
 */
11
class Post
12
{
13
    /**
14
     * @var int Id
15
     * @Id @Column(type="integer") @GeneratedValue
16
     */
17
    protected $id;
18
19
    /**
20
     * @var string Title
21
     * @Column(type="string")
22
     */
23
    protected $title;
24
25
    /**
26
     * @var string Slug
27
     * @Column(type="string", unique=true)
28
     */
29
    protected $slug;
30
31
    /**
32
     * @var string Content
33
     * @Column(type="text")
34
     */
35
    protected $content;
36
37
    /**
38
     * @var DateTime Published at
39
     * @Column(type="datetime")
40
     */
41
    protected $published_at;
42
43
    /**
44
     * @var Category Category
45
     * @ManyToOne(targetEntity="Category", inversedBy="posts")
46
     */
47
    protected $category;
48
49
    /**
50
     * @var ArrayCollection Tags
51
     * @ManyToMany(targetEntity="Tag", cascade={"persist"})
52
     */
53
    protected $tags;
54
55
    public function __construct()
56
    {
57
        $this->tags = new ArrayCollection;
58
    }
59
60
    public function getId()
61
    {
62
        return $this->id;
63
    }
64
65
    public function getTitle()
66
    {
67
        return $this->title;
68
    }
69
70
    public function setTitle($title)
71
    {
72
        $this->title = $title;
73
    }
74
75
    public function getSlug()
76
    {
77
        return $this->slug;
78
    }
79
80
    public function setSlug($slug)
81
    {
82
        $this->slug = $slug;
83
    }
84
85
    public function getContent()
86
    {
87
        return $this->content;
88
    }
89
90
    public function getShortContent()
91
    {
92
        return mb_substr($this->content, 0, mb_strpos($this->content, '<!--more-->'));
93
    }
94
95
    public function setContent($content)
96
    {
97
        $this->content = $content;
98
    }
99
100
    public function getPublishedAt()
101
    {
102
        return $this->published_at;
103
    }
104
105
    public function setPublishedAt(DateTime $published_at)
106
    {
107
        $this->published_at = $published_at;
108
    }
109
110
    public function setCategory($category)
111
    {
112
        $this->category = $category;
113
    }
114
115
    public function getCategory()
116
    {
117
        return $this->category;
118
    }
119
120
    public function getTags()
121
    {
122
        return $this->tags;
123
    }
124
125
    public function addTag(Tag $tag)
126
    {
127
        $this->tags[] = $tag;
128
    }
129
}
130