Passed
Pull Request — master (#84)
by
unknown
12:21
created

Predicates   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
c 1
b 0
f 0
dl 0
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isRoot() 0 3 1
A hasParent() 0 3 1
A isChild() 0 3 1
1
<?php
2
3
namespace Staudenmeir\LaravelAdjacencyList\Eloquent;
4
5
trait Predicates
6
{
7
    /**
8
     * Determine if the model has a parent
9
     *
10
     * @return bool
11
     */
12
    public function hasParent()
13
    {
14
        return $this->{$this->getParentKeyName()} !== null;
0 ignored issues
show
Bug introduced by
It seems like getParentKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        return $this->{$this->/** @scrutinizer ignore-call */ getParentKeyName()} !== null;
Loading history...
15
    }
16
17
    /**
18
     * Determine if the model is a child
19
     *
20
     * @return bool
21
     */
22
    public function isChild()
23
    {
24
        return $this->hasParent();
25
    }
26
27
    /**
28
     * Determine if the model is root
29
     *
30
     * @return bool
31
     */
32
    public function isRoot()
33
    {
34
        return $this->{$this->getParentKeyName()} === null;
35
    }
36
}