Completed
Push — Recipes ( 630f49...c8afb0 )
by Laurent
12:15 queued 03:48
created

FamilyLog::getChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Entity FamilyLog.
5
 *
6
 * PHP Version 7
7
 *
8
 * @author    Quétier Laurent <[email protected]>
9
 * @copyright 2014 Dev-Int GLSR
10
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
11
 *
12
 * @version GIT: <git_id>
13
 *
14
 * @see https://github.com/Dev-Int/glsr
15
 */
16
17
namespace  App\Entity\Settings\Diverse;
18
19
use Doctrine\ORM\Mapping as ORM;
20
use Gedmo\Mapping\Annotation as Gedmo;
21
22
/**
23
 * FamilyLog Entity.
24
 *
25
 * @category Entity
26
 *
27
 * @ORM\Table(name="gs_familylog")
28
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\MaterializedPathRepository")
29
 * @Gedmo\Tree(type="materializedPath")
30
 */
31
class FamilyLog
32
{
33
    /**
34
     * @var int Logistic family id
35
     *
36
     * @ORM\Column(name="id", type="integer")
37
     * @ORM\Id
38
     * @ORM\GeneratedValue(strategy="AUTO")
39
     */
40
    private $flId;
41
42
    /**
43
     * @var string Tree path
44
     *
45
     * @Gedmo\TreePath
46
     * @ORM\Column(length=3000, nullable=true)
47
     */
48
    private $path;
49
50
    /**
51
     * @var string Name of the logistic family
52
     *
53
     * @Gedmo\TreePathSource
54
     * @ORM\Column(name="name", type="string", length=255)
55
     */
56
    private $name;
57
58
    /**
59
     * @var string Slug name
60
     *
61
     * @Gedmo\Slug(fields={"name"})
62
     * @ORM\Column(length=128, unique=true)
63
     */
64
    private $slug;
65
66
    /**
67
     * @var int Parent id
68
     *
69
     * @Gedmo\TreeParent
70
     * @ORM\ManyToOne(targetEntity="App\Entity\Settings\Diverse\FamilyLog", inversedBy="children")
71
     * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
72
     */
73
    private $parent;
74
75
    /**
76
     * @var int Level in the tree
77
     *
78
     * @Gedmo\TreeLevel
79
     * @ORM\Column(type="integer", nullable=true)
80
     */
81
    private $level;
82
83
    /**
84
     * @ORM\OneToMany(targetEntity="App\Entity\Settings\Diverse\FamilyLog", mappedBy="parent")
85
     */
86
    private $children;
87
88
    /**
89
     * Get id.
90
     *
91
     * @return int
92
     */
93
    public function getId()
94
    {
95
        return $this->flId;
96
    }
97
98
    /**
99
     * Set name.
100
     *
101
     * @param string $name Désignation
102
     *
103
     * @return FamilyLog
104
     */
105
    public function setName($name)
106
    {
107
        $this->name = $name;
108
109
        return $this;
110
    }
111
112
    /**
113
     * Get name.
114
     *
115
     * @return string
116
     */
117
    public function getName()
118
    {
119
        return $this->name;
120
    }
121
122
    /**
123
     * Cette méthode permet de faire "echo $familyLog".
124
     * <p>Ainsi, pour "afficher" $familyLog,
125
     * PHP affichera en réalité le retour de cette méthode.<br />
126
     * Ici, le nom, donc "echo $familyLog"
127
     * est équivalent à "echo $familyLog->getName()"</p>.
128
     *
129
     * @return string name
130
     */
131
    public function __toString()
132
    {
133
        return $this->name;
134
    }
135
136
    /**
137
     * Get slug.
138
     *
139
     * @return string
140
     */
141
    public function getSlug()
142
    {
143
        return $this->slug;
144
    }
145
146
    /**
147
     * Set parent.
148
     *
149
     * @param \|null App\Entity\Settings\Diverse\FamilyLog $parent
150
     *
151
     * @return FamilyLog
152
     */
153
    public function setParent(\App\Entity\Settings\Diverse\FamilyLog $parent = null)
154
    {
155
        $this->parent = $parent;
0 ignored issues
show
Documentation Bug introduced by
It seems like $parent can also be of type object<App\Entity\Settings\Diverse\FamilyLog>. However, the property $parent is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
156
157
        return $this;
158
    }
159
160
    /**
161
     * Get parent.
162
     *
163
     * @return \App\Entity\Settings\Diverse\FamilyLog|null
164
     */
165
    public function getParent()
166
    {
167
        return $this->parent;
168
    }
169
170
    /**
171
     * Add children.
172
     *
173
     * @param \App\Entity\Settings\Diverse\FamilyLog $children
174
     *
175
     * @return FamilyLog
176
     */
177
    public function addChild(\App\Entity\Settings\Diverse\FamilyLog $children)
178
    {
179
        $this->children[] = $children;
180
181
        return $this;
182
    }
183
184
    /**
185
     * Remove children.
186
     *
187
     * @param \App\Entity\Settings\Diverse\FamilyLog $children
188
     */
189
    public function removeChild(\App\Entity\Settings\Diverse\FamilyLog $children)
190
    {
191
        $this->children->removeElement($children);
192
    }
193
194
    /**
195
     * Get children.
196
     *
197
     * @return \App\Entity\Settings\Diverse\FamilyLog[]|\Doctrine\Common\Collections\ArrayCollection
198
     */
199
    public function getChildren()
200
    {
201
        return $this->children;
202
    }
203
204
    /**
205
     * Constructor.
206
     */
207
    public function __construct()
208
    {
209
        $this->children = new \Doctrine\Common\Collections\ArrayCollection();
210
    }
211
212
    /**
213
     * Set path.
214
     *
215
     * @param string $path
216
     *
217
     * @return \App\Entity\Settings\Diverse\FamilyLog
218
     */
219
    public function setPath($path)
220
    {
221
        $this->path = $path;
222
223
        return $this;
224
    }
225
226
    /**
227
     * Get path.
228
     *
229
     * @return string
230
     */
231
    public function getPath()
232
    {
233
        return $this->path;
234
    }
235
236
    /**
237
     * Set level.
238
     *
239
     * @param int $level
240
     *
241
     * @return \App\Entity\Settings\Diverse\FamilyLog
242
     */
243
    public function setLevel($level)
244
    {
245
        $this->level = $level;
246
247
        return $this;
248
    }
249
250
    /**
251
     * Get level.
252
     *
253
     * @return int
254
     */
255
    public function getLevel()
256
    {
257
        return $this->level;
258
    }
259
260
    /**
261
     * Allows hierachy display.
262
     *
263
     * @return string
264
     */
265
    public function getIndentedName()
266
    {
267
        $return = '';
268
        if (null !== $this->parent) {
269
            for ($i = 2; $i <= $this->level; ++$i) {
270
                $return .= '|- -';
271
            }
272
            $return .= $this->name;
273
        } else {
274
            $return = '|- '.$this->name;
275
        }
276
277
        return $return;
278
    }
279
}
280