This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @link https://github.com/paulzi/yii2-auto-tree |
||
4 | * @copyright Copyright (c) 2015 PaulZi <[email protected]> |
||
5 | * @license MIT (https://github.com/paulzi/yii2-auto-tree/blob/master/LICENSE) |
||
6 | */ |
||
7 | |||
8 | namespace paulzi\autotree\tests; |
||
9 | |||
10 | use paulzi\autotree\tests\models\NodeAlMp; |
||
11 | use Yii; |
||
12 | |||
13 | /** |
||
14 | * @author PaulZi <[email protected]> |
||
15 | * @group AlMp |
||
16 | */ |
||
17 | class AlMpTest extends AutoTreeTraitTestCase |
||
18 | { |
||
19 | public function getModelClass() |
||
20 | { |
||
21 | return NodeAlMp::className(); |
||
0 ignored issues
–
show
|
|||
22 | } |
||
23 | |||
24 | public function testMakeRootInsert() |
||
25 | { |
||
26 | $node = new NodeAlMp(['slug' => 'r']); |
||
27 | $this->assertTrue($node->makeRoot()->save()); |
||
28 | |||
29 | $node->refresh(); |
||
30 | $this->assertEquals(null, $node->parent_id); |
||
31 | $this->assertEquals(0, $node->sort); |
||
32 | $this->assertEquals(0, $node->depth); |
||
33 | } |
||
34 | |||
35 | public function testMakeRootUpdate() |
||
36 | { |
||
37 | $node = NodeAlMp::findOne(9); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 9 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
38 | $this->assertTrue($node->makeRoot()->save()); |
||
39 | |||
40 | $node->refresh(); |
||
41 | $this->assertEquals(null, $node->parent_id); |
||
42 | $this->assertEquals(0, $node->sort); |
||
43 | $this->assertEquals(0, $node->depth); |
||
44 | } |
||
45 | |||
46 | public function testPrependTo() |
||
47 | { |
||
48 | $node = new NodeAlMp(['slug' => 'new']); |
||
49 | $this->assertTrue($node->prependTo(NodeAlMp::findOne(1))->save()); |
||
0 ignored issues
–
show
It seems like
\paulzi\autotree\tests\models\NodeAlMp::findOne(1) can be null ; however, prependTo() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
The call to
NodeAlMp::findOne() has too many arguments starting with 1 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
50 | |||
51 | $node->refresh(); |
||
52 | $this->assertEquals(1, $node->parent_id); |
||
53 | $this->assertEquals(-101, $node->sort); |
||
54 | $this->assertEquals(1, $node->depth); |
||
55 | } |
||
56 | |||
57 | public function testPrependToAnotherTree() |
||
58 | { |
||
59 | $node = NodeAlMp::findOne(30); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 30 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
60 | $this->assertTrue($node->prependTo(NodeAlMp::findOne(4))->save()); |
||
0 ignored issues
–
show
It seems like
\paulzi\autotree\tests\models\NodeAlMp::findOne(4) can be null ; however, prependTo() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
The call to
NodeAlMp::findOne() has too many arguments starting with 4 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
61 | |||
62 | $node->refresh(); |
||
63 | $this->assertEquals(4, $node->parent_id); |
||
64 | $this->assertEquals(-100, $node->sort); |
||
65 | $this->assertEquals(2, $node->depth); |
||
66 | } |
||
67 | |||
68 | public function testAppendTo() |
||
69 | { |
||
70 | $node = NodeAlMp::findOne(10); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 10 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
71 | $this->assertTrue($node->appendTo(NodeAlMp::findOne(18))->save()); |
||
0 ignored issues
–
show
It seems like
\paulzi\autotree\tests\m...s\NodeAlMp::findOne(18) can be null ; however, appendTo() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
The call to
NodeAlMp::findOne() has too many arguments starting with 18 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
72 | |||
73 | $node->refresh(); |
||
74 | $this->assertEquals(18, $node->parent_id); |
||
75 | $this->assertEquals(0, $node->sort); |
||
76 | $this->assertEquals(4, $node->depth); |
||
77 | } |
||
78 | |||
79 | public function testInsertBefore() |
||
80 | { |
||
81 | $node = new NodeAlMp(['slug' => 'new']); |
||
82 | $this->assertTrue($node->insertBefore(NodeAlMp::findOne(22))->save()); |
||
0 ignored issues
–
show
It seems like
\paulzi\autotree\tests\m...s\NodeAlMp::findOne(22) can be null ; however, insertBefore() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
The call to
NodeAlMp::findOne() has too many arguments starting with 22 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
83 | |||
84 | $node->refresh(); |
||
85 | $this->assertEquals(9, $node->parent_id); |
||
86 | $this->assertEquals(3, $node->sort); |
||
87 | $this->assertEquals(3, $node->depth); |
||
88 | } |
||
89 | |||
90 | public function testInsertAfter() |
||
91 | { |
||
92 | $node = NodeAlMp::findOne(32); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 32 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
93 | $this->assertTrue($node->insertAfter(NodeAlMp::findOne(30))->save()); |
||
0 ignored issues
–
show
It seems like
\paulzi\autotree\tests\m...s\NodeAlMp::findOne(30) can be null ; however, insertAfter() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
The call to
NodeAlMp::findOne() has too many arguments starting with 30 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
94 | |||
95 | $node->refresh(); |
||
96 | $this->assertEquals(26, $node->parent_id); |
||
97 | $this->assertEquals(3, $node->sort); |
||
98 | $this->assertEquals(1, $node->depth); |
||
99 | } |
||
100 | |||
101 | public function testInsertAfterAnotherTree() |
||
102 | { |
||
103 | $node = NodeAlMp::findOne(26); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 26 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
104 | $this->assertTrue($node->insertAfter(NodeAlMp::findOne(21))->save()); |
||
0 ignored issues
–
show
It seems like
\paulzi\autotree\tests\m...s\NodeAlMp::findOne(21) can be null ; however, insertAfter() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
Loading history...
The call to
NodeAlMp::findOne() has too many arguments starting with 21 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
105 | |||
106 | $node->refresh(); |
||
107 | $this->assertEquals(9, $node->parent_id); |
||
108 | $this->assertEquals(3, $node->sort); |
||
109 | $this->assertEquals(3, $node->depth); |
||
110 | } |
||
111 | |||
112 | public function testDelete() |
||
113 | { |
||
114 | $this->assertEquals(1, NodeAlMp::findOne(30)->delete()); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 30 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
115 | $this->assertEquals(null, NodeAlMp::findOne(30)); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 30 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
116 | } |
||
117 | |||
118 | public function testDeleteWithChildren() |
||
119 | { |
||
120 | $this->assertEquals(10, NodeAlMp::findOne(4)->deleteWithChildren()); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 4 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
121 | $this->assertEquals(null, NodeAlMp::findOne(24)); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 24 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
122 | $this->assertEquals(15, NodeAlMp::findOne(1)->deleteWithChildren()); |
||
0 ignored issues
–
show
The call to
NodeAlMp::findOne() has too many arguments starting with 1 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
123 | } |
||
124 | } |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.