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 | * Created by: Marko Kungla @ OkramLabs on Aug 6, 2012 - 10:02:48 |
||
4 | * Contact: [email protected] - https://okramlabs.com |
||
5 | * @copyright 2015 OkramLabs - https://okramlabs.com |
||
6 | * @license MIT |
||
7 | * |
||
8 | * Package name:libhowi-filesystem |
||
9 | * @category HOWI3 |
||
10 | * @package libhowi |
||
11 | * @subpackage filesystem |
||
12 | * |
||
13 | * Lang: PHP |
||
14 | * Encoding: UTF-8 |
||
15 | * File: DirectoryPlaceholderObject.inc |
||
16 | * @link https:// |
||
17 | ******************************************************************** |
||
18 | * Contributors: |
||
19 | * @author Marko Kungla <[email protected]> |
||
20 | * Github: https://github.com/mkungla |
||
21 | ******************************************************************** |
||
22 | * Comments: |
||
23 | */ |
||
24 | namespace HOWI3\libhowi\Filesystem\php7\Objects; |
||
25 | |||
26 | use \Directory; |
||
27 | use \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\DirectoryPlaceholderInterface; |
||
28 | use \HOWI3\libhowi\Filesystem\Commons\SharedMethodsInterface; |
||
29 | use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse; |
||
30 | use \HOWI3\libhowi\Filesystem\php7\TraitForSharedMethods; |
||
31 | |||
32 | View Code Duplication | class DirectoryPlaceholderObject extends Directory implements DirectoryPlaceholderInterface, |
|
0 ignored issues
–
show
|
|||
33 | SharedMethodsInterface |
||
34 | { |
||
35 | use TraitForResponse; |
||
36 | use TraitForSharedMethods; |
||
37 | |||
38 | public $path = ''; |
||
39 | |||
40 | public $handle; |
||
41 | |||
42 | private $mode = 750; |
||
43 | |||
44 | private $recursive = true; |
||
45 | |||
46 | private $context = false; |
||
47 | |||
48 | /** |
||
49 | * |
||
50 | * {@inheritDoc} |
||
51 | * |
||
52 | */ |
||
53 | 6 | public function __construct($pathname = false, $recursive = true, $mode = false, $context = false, $logfile = false, |
|
54 | $loglevel = false, $UID = false, $username = false) |
||
55 | { |
||
56 | 6 | if (! empty($logfile) && file_exists($logfile) && ! empty($loglevel)) { |
|
57 | 5 | $this->setLogfile($logfile); |
|
0 ignored issues
–
show
$logfile is of type boolean , but the function expects a false|string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
58 | 5 | $this->setLoglevel($loglevel); |
|
0 ignored issues
–
show
$loglevel is of type boolean , but the function expects a integer .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
59 | 5 | $this->setUID($UID); |
|
60 | 5 | $this->setUsername($username); |
|
0 ignored issues
–
show
$username is of type boolean , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
61 | } |
||
62 | |||
63 | 6 | $pathname = (! empty($pathname) ? $this->makeAbsolute($pathname) : $this->path); |
|
64 | |||
65 | 6 | $HID = md5($pathname); |
|
66 | |||
67 | 6 | $this->dirsetPath($pathname, $HID); |
|
0 ignored issues
–
show
It seems like
$pathname defined by !empty($pathname) ? $thi...pathname) : $this->path on line 63 can also be of type string ; however, HOWI3\libhowi\Filesystem...derObject::dirsetPath() does only seem to accept boolean , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() $HID is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
68 | 6 | $this->dirsetMode(! empty($mode) ? $mode : $this->mode, $HID); |
|
0 ignored issues
–
show
It seems like
!empty($mode) ? $mode : $this->mode can also be of type integer ; however, HOWI3\libhowi\Filesystem...derObject::dirsetMode() does only seem to accept boolean , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() $HID is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
69 | |||
70 | 6 | $this->dirsetRecursive(! empty($recursive) ? true : false, $HID); |
|
0 ignored issues
–
show
$HID is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
71 | |||
72 | 6 | $context = ! empty($context) ? $this->dirsetContext($context, $HID) : false; |
|
0 ignored issues
–
show
$HID is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() $context is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
73 | |||
74 | 6 | $this->info(701, $pathname); |
|
0 ignored issues
–
show
It seems like
$pathname defined by !empty($pathname) ? $thi...pathname) : $this->path on line 63 can also be of type boolean ; however, HOWI3\libhowi\Filesystem...raitForResponse::info() does only seem to accept false|string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
75 | 6 | $this->response()->setStatus($this->dirCreate($HID)); |
|
0 ignored issues
–
show
$HID is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
76 | 6 | } |
|
77 | |||
78 | /** |
||
79 | * |
||
80 | * {@inheritDoc} |
||
81 | * |
||
82 | */ |
||
83 | 6 | public function dirsetPath($pathname = false, $HID = false) |
|
84 | { |
||
85 | 6 | if (! empty($pathname) && is_string($pathname) && ! empty($HID)) { |
|
86 | |||
87 | 6 | $this->path = $this->makeAbsolute($pathname); |
|
0 ignored issues
–
show
$pathname is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() It seems like
$this->makeAbsolute($pathname) can also be of type boolean . However, the property $path is declared as type string . 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 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;
}
![]() |
|||
88 | |||
89 | 6 | return true; |
|
90 | } else { |
||
91 | 1 | $this->debug(802, 'DirectoryTrait->dirsetPath'); |
|
92 | 1 | return false; |
|
93 | } |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * |
||
98 | * {@inheritDoc} |
||
99 | * |
||
100 | */ |
||
101 | 6 | public function dirsetMode($mode = false, $HID = false) |
|
102 | { |
||
103 | 6 | if (! empty($HID) && ! empty($mode) && is_int($mode)) { |
|
104 | 6 | $this->mode = $mode; |
|
105 | 6 | return true; |
|
106 | } else { |
||
107 | |||
108 | 1 | $this->debug(802, 'DirectoryTrait->dirsetMode'); |
|
109 | 1 | return false; |
|
110 | } |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * |
||
115 | * {@inheritDoc} |
||
116 | * |
||
117 | */ |
||
118 | 6 | public function dirsetRecursive($recursive = false, $HID = false) |
|
119 | { |
||
120 | 6 | if (! empty($HID) && is_bool($recursive)) { |
|
121 | 6 | $this->recursive = $recursive; |
|
122 | 6 | return true; |
|
123 | } else { |
||
124 | 1 | $this->debug(802, 'DirectoryTrait->dirsetRecursive'); |
|
125 | } |
||
126 | |||
127 | 1 | return false; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * |
||
132 | * {@inheritDoc} |
||
133 | * |
||
134 | */ |
||
135 | 2 | public function dirsetContext($context = false, $HID = false) |
|
136 | { |
||
137 | 2 | if (! empty($HID) && is_resource($context)) { |
|
138 | 1 | $this->context = $context; |
|
0 ignored issues
–
show
It seems like
$context of type resource is incompatible with the declared type boolean of property $context .
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.. ![]() |
|||
139 | 1 | return true; |
|
140 | } |
||
141 | |||
142 | else { |
||
143 | 1 | $this->debug(802, 'DirectoryTrait->dirsetContext'); |
|
144 | 1 | return false; |
|
145 | } |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * |
||
150 | * {@inheritDoc} |
||
151 | * |
||
152 | */ |
||
153 | 6 | public function dirCreate($HID = false) |
|
154 | { |
||
155 | 6 | if ((! is_dir(dirname($this->path)) && $this->recursive === false) || |
|
156 | 6 | is_dir(dirname($this->path)) && ! $this->isWritable(dirname($this->path))) { |
|
0 ignored issues
–
show
dirname($this->path) is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
157 | 2 | $this->warning(502, $this->path); |
|
158 | 2 | $result = false; |
|
159 | } else { |
||
160 | 5 | if (! empty($HID) && ! $this->exists($this->path) && ! empty($this->context)) { |
|
0 ignored issues
–
show
$this->path is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
161 | 1 | $result = mkdir($this->path, octdec(str_pad($this->mode, 4, 0, STR_PAD_LEFT)), |
|
162 | 1 | $this->recursive, $this->context); |
|
163 | } |
||
164 | 5 | if (! empty($HID) && ! $this->exists($this->path) && empty($this->context)) { |
|
0 ignored issues
–
show
$this->path is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
165 | |||
166 | 5 | $result = mkdir($this->path, octdec(str_pad($this->mode, 4, 0, STR_PAD_LEFT)), true); |
|
167 | } |
||
168 | } |
||
169 | 6 | return $result; |
|
0 ignored issues
–
show
The variable
$result does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
170 | } |
||
171 | } |
||
172 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.