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 ( b2510c...ee0bb8 )
by
unknown
12:46
created

TreeRepository::getChildren()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 2
ccs 0
cts 16
cp 0
crap 12
rs 9.4285
1
<?php
2
3
namespace SleepingOwl\Admin\Repositories;
4
5
use SleepingOwl\Admin\Display\Tree\BaumNodeType;
6
use SleepingOwl\Admin\Display\Tree\SimpleTreeType;
7
use SleepingOwl\Admin\Display\Tree\KalnoyNestedsetType;
8
use SleepingOwl\Admin\Exceptions\Display\DisplayTreeException;
9
use SleepingOwl\Admin\Contracts\Display\Tree\TreeTypeInterface;
10
use SleepingOwl\Admin\Contracts\Repositories\TreeRepositoryInterface;
11
12
class TreeRepository extends BaseRepository implements TreeRepositoryInterface
13
{
14
    /**
15
     * Parent field name.
16
     * @var string
17
     */
18
    protected $parentField = 'parent_id';
19
20
    /**
21
     * Order field name.
22
     * @var string
23
     */
24
    protected $orderField = 'order';
25
26
    /**
27
     * Root parent id value.
28
     * @var null
29
     */
30
    protected $rootParentId = null;
31
32
    /**
33
     * @var TreeTypeInterface
34
     */
35
    protected $treeType;
36
37
    /**
38
     * @param string $treeType
39
     */
40
    public function __construct($treeType = null)
41
    {
42
        if (! is_null($treeType)) {
43
            $this->setTreeType($treeType);
44
        }
45
    }
46
47
    /**
48
     * @param string $treeType
49
     *
50
     * @throws DisplayTreeException
51
     */
52
    public function setTreeType($treeType)
53
    {
54
        $this->treeType = new $treeType($this);
55
56
        if (! ($this->treeType instanceof TreeTypeInterface)) {
57
            throw new DisplayTreeException('Tree type class must be instanced of [SleepingOwl\Admin\Contracts\Display\Tree\TreeTypeInterface]');
58
        }
59
    }
60
61
    /**
62
     * @param string $class
63
     *
64
     * @return $this
65
     */
66
    public function setClass($class)
67
    {
68
        parent::setClass($class);
69
70
        if (is_null($this->treeType)) {
71
            $this->detectType();
72
        }
73
74
        return $this;
75
    }
76
77
    /**
78
     * Get tree structure.
79
     *
80
     * @param \Illuminate\Database\Eloquent\Collection $collection
81
     *
82
     * @return mixed
83
     */
84
    public function getTree(\Illuminate\Database\Eloquent\Collection $collection)
85
    {
86
        return $this->treeType->getTree($collection);
87
    }
88
89
    /**
90
     * Get parent field name.
91
     *
92
     * @return string
93
     */
94
    public function getParentField()
95
    {
96
        return $this->parentField;
97
    }
98
99
    /**
100
     * @param string $parentField
101
     *
102
     * @return $this
103
     */
104
    public function setParentField($parentField)
105
    {
106
        $this->parentField = $parentField;
107
108
        return $this;
109
    }
110
111
    /**
112
     * Get order field name.
113
     *
114
     * @return string
115
     */
116
    public function getOrderField()
117
    {
118
        return $this->orderField;
119
    }
120
121
    /**
122
     * @param string $orderField
123
     *
124
     * @return $this
125
     */
126
    public function setOrderField($orderField)
127
    {
128
        $this->orderField = $orderField;
129
130
        return $this;
131
    }
132
133
    /**
134
     * Get or set parent field name.
135
     *
136
     * @return string
137
     */
138
    public function getRootParentId()
139
    {
140
        return $this->rootParentId;
141
    }
142
143
    /**
144
     * @param string $rootParentId
145
     *
146
     * @return $this
147
     */
148
    public function setRootParentId($rootParentId)
149
    {
150
        $this->rootParentId = $rootParentId;
0 ignored issues
show
Documentation Bug introduced by
It seems like $rootParentId of type string is incompatible with the declared type null of property $rootParentId.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
151
152
        return $this;
153
    }
154
155
    /**
156
     * Reorder tree by $data value.
157
     *
158
     * @param $data
159
     */
160
    public function reorder(array $data)
161
    {
162
        $this->treeType->reorder($data);
163
    }
164
165
    /**
166
     * Detect tree type.
167
     * @return $this
168
     */
169
    protected function detectType()
170
    {
171
        $model = $this->getModel();
172
173
        $type = SimpleTreeType::class;
174
175
        if ($model instanceof \Baum\Node) {
0 ignored issues
show
Bug introduced by
The class Baum\Node does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
176
            $type = BaumNodeType::class;
177
        } elseif (class_exists('Kalnoy\Nestedset\Node') and $model instanceof \Kalnoy\Nestedset\Node) {
0 ignored issues
show
Bug introduced by
The class Kalnoy\Nestedset\Node does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
178
            $type = KalnoyNestedsetType::class;
179
        } elseif (function_exists('trait_uses_recursive') and $traits = trait_uses_recursive($model) and in_array('Kalnoy\Nestedset\NodeTrait', $traits)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
180
            $type = KalnoyNestedsetType::class;
181
        } elseif ($traits = class_uses($model) and in_array('Kalnoy\Nestedset\NodeTrait', $traits)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
182
            $type = KalnoyNestedsetType::class;
183
        }
184
185
        $this->setTreeType($type);
186
    }
187
}
188