Category::removePost()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * @ORM\Entity
10
 * @ORM\Table(name="categories")
11
 */
12
class Category
13
{
14
    /**
15
     * @ORM\Id
16
     * @ORM\GeneratedValue
17
     * @ORM\Column(type="integer")
18
     */
19
    private $id;
20
21
    /**
22
     * @ORM\Column(type="string", length=255)
23
     */
24
    private $name;
25
26
    /**
27
     * @ORM\OneToMany(targetEntity=Post::class, mappedBy="category")
28
     */
29
    private $posts;
30
31
    public function __construct()
32
    {
33
        $this->posts = new ArrayCollection();
34
    }
35
36
    public function getId()
37
    {
38
        return $this->id;
39
    }
40
41
    public function getName(): ?string
42
    {
43
        return $this->name;
44
    }
45
46
    public function setName($name)
47
    {
48
        $this->name = $name;
49
    }
50
51
    public function getPosts()
52
    {
53
        return $this->posts;
54
    }
55
56
    public function addPost(Post $post)
57
    {
58
        if (!$this->posts->contains($post)) {
59
            $this->posts[] = $post;
60
            $post->setCategory($this);
61
        }
62
    }
63
64
    public function removePost(Post $post)
65
    {
66
        if ($this->posts->contains($post)) {
67
            $this->posts->removeElement($post);
68
            // set the owning side to null (unless already changed)
69
            if ($post->getCategory() === $this) {
70
                $post->setCategory(null);
71
            }
72
        }
73
    }
74
}
75