Passed
Pull Request — master (#49)
by
unknown
13:49
created

Tag::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog\Entity;
6
7
use Cycle\Annotated\Annotation\Column;
8
use Cycle\Annotated\Annotation\Entity;
9
use Cycle\Annotated\Annotation\Relation\ManyToMany;
10
use Cycle\Annotated\Annotation\Table;
11
use Cycle\Annotated\Annotation\Table\Index;
12
use Cycle\ORM\Relation\Pivoted\PivotedCollection;
13
use DateTimeImmutable;
14
use Doctrine\Common\Collections\ArrayCollection;
15
16
/**
17
 * @Entity(repository="App\Blog\Tag\TagRepository", mapper="App\Blog\Tag\TagMapper")
18
 * @Table(
19
 *     indexes={
20
 *         @Index(columns={"label"}, unique=true)
21
 *     }
22
 * )
23
 */
24
class Tag
25
{
26
    /**
27
     * @Column(type="primary")
28
     */
29
    private ?int $id = null;
30
31
    /**
32
     * @Column(type="string(255)")
33
     */
34
    private string $label;
35
36
    /**
37
     * @Column(type="datetime")
38
     */
39
    private DateTimeImmutable $created_at;
40
41
    /**
42
     * @ManyToMany(target="App\Blog\Entity\Post", though="PostTag", fkAction="CASCADE", indexCreate=false)
43
     * @var Post[]|PivotedCollection
44
     */
45
    private $posts;
46
47
    public function __construct(string $label)
48
    {
49
        $this->label = $label;
50
        $this->created_at = new DateTimeImmutable();
51
        $this->posts = new PivotedCollection();
52
    }
53
54
    public function getId(): ?int
55
    {
56
        return $this->id;
57
    }
58
59
    public function getLabel(): string
60
    {
61
        return $this->label;
62
    }
63
64
    public function setLabel(string $label): void
65
    {
66
        $this->label = $label;
67
    }
68
69
    public function getCreatedAt(): DateTimeImmutable
70
    {
71
        return $this->created_at;
72
    }
73
74
    /**
75
     * @return ArrayCollection|Post[]
76
     */
77
    public function getPosts(): ArrayCollection
78
    {
79
        return $this->posts;
80
    }
81
82
    public function addPost(Post $post): void
83
    {
84
        $this->posts->add($post);
85
    }
86
}
87