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

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