Completed
Push — master ( 3a917b...8faa80 )
by Alexander
15s queued 12s
created

Tag   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A getCreatedAt() 0 3 1
A getLabel() 0 3 1
A addPost() 0 3 1
A __construct() 0 5 1
A setLabel() 0 3 1
A getPosts() 0 3 1
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