GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( b52382...825938 )
by
unknown
07:13
created

AdjacencyTrait::getParent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Models\Sql\Traits;
15
16
// ------------------------------------------------------------------------
17
18
/**
19
 * Class AdjacencyTrait
20
 *
21
 * @package O2System\Framework\Models\Sql\Traits
22
 */
23
trait AdjacencyTrait
24
{
25
    /**
26
     * AdjacencyTrait::$parentKey
27
     *
28
     * @var string
29
     */
30
    public $parentKey = 'id_parent';
31
32
    /**
33
     * AdjacencyTrait::$adjacency
34
     *
35
     * @var bool
36
     */
37
    protected $adjacency = true;
38
39
    // ------------------------------------------------------------------------
40
41
    /**
42
     * AdjacencyTrait::getParent
43
     *
44
     * @param int $id
45
     *
46
     * @return bool|\O2System\Framework\Models\Sql\DataObjects\Result\Row
47
     */
48
    public function getParent($id)
49
    {
50
        if ($parent = $this->qb
51
            ->from($this->table)
52
            ->where($this->parentKey, $id)
53
            ->get(1)) {
54
            if ($parent->count() == 1) {
55
                return $parent;
56
            }
57
        }
58
59
        return false;
60
    }
61
62
    // ------------------------------------------------------------------------
63
64
    /**
65
     * AdjacencyTrait::getNumOfParent
66
     *
67
     * @param int $id
68
     *
69
     * @return int
70
     */
71
    public function getNumOfParent($id)
72
    {
73
        if ($parents = $this->qb
74
            ->table($this->table)
75
            ->select('id')
76
            ->where('id', $id)
77
            ->get(1)) {
78
            return $parents->count();
79
        }
80
81
        return 0;
82
    }
83
84
    // ------------------------------------------------------------------------
85
86
    /**
87
     * AdjacencyTrait::hasParent
88
     *
89
     * @param int $id
90
     *
91
     * @return bool
92
     */
93
    public function hasParent($id)
94
    {
95
        if (($numParents = $this->getNumOfParent($id)) > 0) {
0 ignored issues
show
Unused Code introduced by
The assignment to $numParents is dead and can be removed.
Loading history...
96
            return true;
97
        }
98
99
        return false;
100
    }
101
102
    // ------------------------------------------------------------------------
103
104
    /**
105
     * AdjacencyTrait::getChilds
106
     *
107
     * @param int $idParent
108
     *
109
     * @return bool|\O2System\Framework\Models\Sql\DataObjects\Result
110
     */
111
    public function getChilds($idParent)
112
    {
113
        if ($childs = $this->qb
114
            ->from($this->table)
115
            ->where($this->parentKey, $idParent)
116
            ->get()) {
117
            if ($childs->count() > 0) {
118
                return $childs;
119
            }
120
        }
121
122
        return false;
123
    }
124
125
    // ------------------------------------------------------------------------
126
127
    /**
128
     * AdjacencyTrait::getNumChilds
129
     *
130
     * @param int $idParent
131
     *
132
     * @return bool
133
     */
134
    public function getNumOfChilds($idParent)
135
    {
136
        if ($childs = $this->getChilds($idParent)) {
137
            return $childs->count();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $childs->count() returns the type integer which is incompatible with the documented return type boolean.
Loading history...
138
        }
139
140
        return 0;
0 ignored issues
show
Bug Best Practice introduced by
The expression return 0 returns the type integer which is incompatible with the documented return type boolean.
Loading history...
141
    }
142
143
    // ------------------------------------------------------------------------
144
145
    /**
146
     * AdjacencyTrait::hasChilds
147
     *
148
     * @param int $idParent
149
     *
150
     * @return bool
151
     */
152
    public function hasChilds($idParent)
153
    {
154
        if ($numOfChilds = $this->getNumOfChilds($idParent)) {
155
            return (bool)($numOfChilds == 0 ? false : true);
156
        }
157
158
        return false;
159
    }
160
}