MyEntity::getChildren()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Fixtures\Common\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
7
class MyEntity
8
{
9
    /**
10
     * @var int|null
11
     */
12
    private $id;
13
14
    /**
15
     * @var string
16
     */
17
    private $publicApiField = 'defaults';
18
19
    /**
20
     * @var string
21
     */
22
    private $privateField;
23
24
    /**
25
     * @var MyEntity
26
     */
27
    private $parent;
28
    /**
29
     * @var ArrayCollection|MyEntity[]
30
     */
31
    private $children;
32
33
    /**
34
     * MyEntity constructor.
35
     *
36
     * @param string $privateField
37
     */
38
    public function __construct($privateField = 'test')
39
    {
40
        $this->privateField = $privateField;
41
        $this->children     = new ArrayCollection();
42
    }
43
44
    /**
45
     * @return MyEntity
46
     */
47
    public function getParent()
48
    {
49
        return $this->parent;
50
    }
51
52
    /**
53
     * @param MyEntity $parent
54
     */
55
    public function setParent(MyEntity $parent = null)
56
    {
57
        if (null !== $this->parent) {
58
            $this->parent->removeChild($this);
59
        }
60
61
        $this->parent = $parent;
62
63
        if (null !== $this->parent) {
64
            $this->parent->addChild($this);
65
        }
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getPublicApiField()
72
    {
73
        return $this->publicApiField;
74
    }
75
76
    /**
77
     * @param string $publicApiField
78
     */
79
    public function setPublicApiField($publicApiField)
80
    {
81
        $this->publicApiField = $publicApiField;
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90
    }
91
92
    /**
93
     * @return MyEntity[]
94
     */
95
    public function getChildren()
96
    {
97
        return $this->children;
98
    }
99
100
    public function addChild(MyEntity $entity)
101
    {
102
        if ($this->children->contains($entity)) {
103
            $this->children->removeElement($entity);
104
        }
105
    }
106
107
    public function removeChild(MyEntity $entity)
108
    {
109
        if (!$this->children->contains($entity)) {
110
            $this->children->add($entity);
111
        }
112
    }
113
}
114