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 | * Module |
|||||||||||
4 | * |
|||||||||||
5 | * @package Intraface |
|||||||||||
6 | * @author Lars Olesen <[email protected]> |
|||||||||||
7 | * @author Sune Jensen <[email protected]> |
|||||||||||
8 | * @since 0.1.0 |
|||||||||||
9 | * @version @package-version@ |
|||||||||||
10 | */ |
|||||||||||
11 | class Intraface_ModuleHandler |
|||||||||||
12 | { |
|||||||||||
13 | private $user; |
|||||||||||
14 | private $internet; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
15 | private $modules = array(); |
|||||||||||
16 | private $primary_module_name; |
|||||||||||
17 | private $primary_module_object; |
|||||||||||
18 | private $shared = array(); |
|||||||||||
19 | ||||||||||||
20 | 94 | public function __construct($intranet = '', $user = '') |
||||||||||
21 | { |
|||||||||||
22 | 94 | $this->user = $user; |
||||||||||
23 | 94 | $this->intranet = $intranet; |
||||||||||
0 ignored issues
–
show
The property
intranet does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
||||||||||||
24 | 94 | } |
||||||||||
25 | ||||||||||||
26 | /** |
|||||||||||
27 | * Returns the primary module |
|||||||||||
28 | * |
|||||||||||
29 | * Used for instance in Page to give the correct submenu. |
|||||||||||
30 | * |
|||||||||||
31 | * @return module object or false |
|||||||||||
32 | */ |
|||||||||||
33 | 1 | function getPrimaryModule() |
||||||||||
34 | { |
|||||||||||
35 | 1 | if (!empty($this->modules[$this->primary_module_name]) and is_object($this->modules[$this->primary_module_name])) { |
||||||||||
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):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like 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-FlowOne 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 // 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. ![]() |
||||||||||||
36 | 1 | return($this->modules[$this->primary_module_name]); |
||||||||||
37 | } else { |
|||||||||||
38 | 1 | return false; |
||||||||||
0 ignored issues
–
show
The return type of
return false; (false ) is incompatible with the return type documented by Intraface_ModuleHandler::getPrimaryModule of type Module .
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: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
||||||||||||
39 | } |
|||||||||||
40 | } |
|||||||||||
41 | ||||||||||||
42 | 28 | function setPrimaryModule($module_name) |
||||||||||
43 | { |
|||||||||||
44 | 28 | if (!empty($this->primary_module_object) and is_object($this->primary_module_object)) { |
||||||||||
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):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like 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-FlowOne 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 // 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. ![]() |
||||||||||||
45 | throw new Exception('Primary module has been set'); |
|||||||||||
46 | } else { |
|||||||||||
47 | 28 | $module = $this->useModule($module_name); |
||||||||||
48 | ||||||||||||
49 | 27 | if (is_object($module)) { |
||||||||||
50 | 27 | $this->primary_module_name = $module_name; |
||||||||||
51 | ||||||||||||
52 | // Finds dependent modules |
|||||||||||
53 | // @todo Maybe this should be moved to useModule() |
|||||||||||
54 | 27 | $dependent_modules = $module->getDependentModules(); |
||||||||||
55 | ||||||||||||
56 | 27 | foreach ($dependent_modules as $dependent) { |
||||||||||
57 | $no_use = $this->useModule($dependent); |
|||||||||||
0 ignored issues
–
show
$no_use 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 ![]() |
||||||||||||
58 | 27 | } |
||||||||||
59 | ||||||||||||
60 | 27 | return $module; |
||||||||||
61 | } else { |
|||||||||||
62 | // @todo Den fejlmeddelse er egentlig irrelevant, da useModul ikke enten returnere et objekt eller throw new Exception. |
|||||||||||
63 | throw new Exception('Du har ikke adgang til modulet'); |
|||||||||||
64 | } |
|||||||||||
65 | } |
|||||||||||
66 | } |
|||||||||||
67 | ||||||||||||
68 | /** |
|||||||||||
69 | * useModule() |
|||||||||||
70 | * |
|||||||||||
71 | * @todo Need to handle access |
|||||||||||
72 | * |
|||||||||||
73 | * @param string $module_name |
|||||||||||
74 | * @param boolean $ignore_user_access |
|||||||||||
75 | * |
|||||||||||
76 | * @return object $module |
|||||||||||
77 | */ |
|||||||||||
78 | 90 | public function useModule($module_name, $ignore_user_access = false) |
||||||||||
79 | { |
|||||||||||
80 | 90 | if (!self::isValidModuleName($module_name)) { |
||||||||||
81 | 1 | throw new Exception($module_name . ' is not a valid module name'); |
||||||||||
82 | } |
|||||||||||
83 | ||||||||||||
84 | 89 | if (!empty($this->modules[$module_name]) and is_object($this->modules[$module_name])) { |
||||||||||
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):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like 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-FlowOne 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 // 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. ![]() |
||||||||||||
85 | 25 | return $this->modules[$module_name]; |
||||||||||
86 | } |
|||||||||||
87 | ||||||||||||
88 | 89 | $this->modules[$module_name] = $module_name; |
||||||||||
89 | ||||||||||||
90 | // @todo check whether a module has any limitations in access here? - we have not asked for shared |
|||||||||||
91 | ||||||||||||
92 | // access control here |
|||||||||||
93 | 89 | $access = false; |
||||||||||
94 | ||||||||||||
95 | 89 | if (!is_object($this->user)) { |
||||||||||
96 | 9 | if (!is_object($this->intranet)) { |
||||||||||
97 | 2 | throw new Exception('Cannot use a module when no intranet is available'); |
||||||||||
98 | } |
|||||||||||
99 | // Det er et weblogin. |
|||||||||||
100 | 7 | if ($this->intranet->hasModuleAccess($module_name)) { |
||||||||||
101 | 6 | $access = true; |
||||||||||
102 | 6 | } |
||||||||||
103 | 87 | } elseif ($ignore_user_access) { |
||||||||||
104 | if (!is_object($this->intranet)) { |
|||||||||||
105 | throw new Exception('Cannot use a module when no intranet is available'); |
|||||||||||
106 | } |
|||||||||||
107 | // Skal kun kontrollere om intranettet har adgang, for at benytte modullet |
|||||||||||
108 | if ($this->intranet->hasModuleAccess($module_name)) { |
|||||||||||
109 | $access = true; |
|||||||||||
110 | } |
|||||||||||
111 | } else { |
|||||||||||
112 | // Almindelig login |
|||||||||||
113 | 80 | if ($this->user->hasModuleAccess($module_name)) { |
||||||||||
114 | 79 | $access = true; |
||||||||||
115 | 79 | } |
||||||||||
116 | } |
|||||||||||
117 | ||||||||||||
118 | 87 | if ($access !== true) { |
||||||||||
119 | 2 | throw new Exception('You need access to a required module to see this page, maybe it is ' . $module_name); |
||||||||||
120 | } |
|||||||||||
121 | ||||||||||||
122 | 85 | $main_class_name = "Main" . ucfirst($module_name); |
||||||||||
123 | 85 | $main_class_path = PATH_INCLUDE_MODULE . $module_name . "/" . $main_class_name . ".php"; |
||||||||||
124 | ||||||||||||
125 | 85 | if (file_exists($main_class_path)) { |
||||||||||
126 | 85 | require_once($main_class_path); |
||||||||||
127 | 85 | $object = new $main_class_name; |
||||||||||
128 | 85 | $object->load($this); |
||||||||||
129 | 85 | $this->modules[$module_name] = $object; |
||||||||||
130 | 85 | return $object; |
||||||||||
131 | } else { |
|||||||||||
132 | // @TODO this should not fail as hard - but what should happen then? |
|||||||||||
133 | throw new Exception('ModuleHandler: ' . $main_class_path . ' does not exist'); |
|||||||||||
134 | } |
|||||||||||
135 | } |
|||||||||||
136 | ||||||||||||
137 | /** |
|||||||||||
138 | * Gives access to a shared module |
|||||||||||
139 | * |
|||||||||||
140 | * @param string $shared_name Name on module to load |
|||||||||||
141 | * |
|||||||||||
142 | * @return object or false |
|||||||||||
143 | */ |
|||||||||||
144 | 63 | public function useShared($shared_name) |
||||||||||
145 | { |
|||||||||||
146 | 63 | if (!self::isValidModuleName($shared_name)) { |
||||||||||
147 | throw new Exception($shared_name. ' is not a valid shared module name'); |
|||||||||||
148 | } |
|||||||||||
149 | ||||||||||||
150 | // Tjekker om shared allerede er loaded |
|||||||||||
151 | 63 | if (!empty($this->shared[$shared_name]) and is_object($this->shared[$shared_name])) { |
||||||||||
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):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like 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-FlowOne 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 // 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. ![]() |
||||||||||||
152 | 36 | return $this->shared[$shared_name]; |
||||||||||
153 | } |
|||||||||||
154 | ||||||||||||
155 | 63 | $main_shared_name = 'Shared' . ucfirst($shared_name); |
||||||||||
156 | 63 | $main_shared_path = PATH_INCLUDE_SHARED . $shared_name . '/' . $main_shared_name . '.php'; |
||||||||||
157 | ||||||||||||
158 | 63 | if (file_exists($main_shared_path)) { |
||||||||||
159 | 63 | require_once $main_shared_path; |
||||||||||
160 | 63 | $object = new $main_shared_name; |
||||||||||
161 | 63 | $object->load(); |
||||||||||
162 | 63 | $this->shared[$shared_name] = $object; |
||||||||||
163 | 63 | return $object; |
||||||||||
164 | } else { |
|||||||||||
165 | throw new Exception($shared_name . ' cannot be found on ' . $main_shared_path . ' with PATH_INCLUDE_SHARED: ' . PATH_INCLUDE_SHARED); |
|||||||||||
166 | } |
|||||||||||
167 | } |
|||||||||||
168 | ||||||||||||
169 | /** |
|||||||||||
170 | * getModule() |
|||||||||||
171 | * |
|||||||||||
172 | * @param string $module_name |
|||||||||||
0 ignored issues
–
show
There is no parameter named
$module_name . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
||||||||||||
173 | * |
|||||||||||
174 | * @return object |
|||||||||||
175 | */ |
|||||||||||
176 | 2 | function getModule($name) |
||||||||||
177 | { |
|||||||||||
178 | 2 | if (is_object($this->modules[$name])) { |
||||||||||
179 | 2 | return($this->modules[$name]); |
||||||||||
180 | } else { |
|||||||||||
181 | throw new Exception('getModule() module ' . $name . ' not loaded'); |
|||||||||||
182 | } |
|||||||||||
183 | } |
|||||||||||
184 | ||||||||||||
185 | /** |
|||||||||||
186 | * getModules() |
|||||||||||
187 | * |
|||||||||||
188 | * @param string $order_by |
|||||||||||
189 | * |
|||||||||||
190 | * @return array |
|||||||||||
191 | */ |
|||||||||||
192 | 2 | public static function getModules($db, $order_by = 'frontpage_index') |
||||||||||
193 | { |
|||||||||||
194 | 2 | $modules = array(); |
||||||||||
195 | ||||||||||||
196 | 2 | if ($order_by != '') { |
||||||||||
197 | 2 | $order_by = "ORDER BY ".$db->quoteIdentifier($order_by, 'text'); |
||||||||||
198 | 2 | } |
||||||||||
199 | ||||||||||||
200 | 2 | $i = 0; |
||||||||||
201 | 2 | $result = $db->query("SELECT id, menu_label, name, show_menu FROM module WHERE active = 1 ".$order_by); |
||||||||||
202 | 2 | if (PEAR::isError($result)) { |
||||||||||
203 | throw new Exception($result->getUserInfo()); |
|||||||||||
204 | } |
|||||||||||
205 | 2 | while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
||||||||||
206 | 2 | $modules[$i]['id'] = $row['id']; |
||||||||||
207 | 2 | $modules[$i]['name'] = $row['name']; |
||||||||||
208 | 2 | $modules[$i]['menu_label'] = $row['menu_label']; |
||||||||||
209 | 2 | $modules[$i]['show_menu'] = $row['show_menu']; |
||||||||||
210 | ||||||||||||
211 | 2 | $j = 0; |
||||||||||
212 | 2 | $result_sub = $db->query("SELECT id, description FROM module_sub_access WHERE active = 1 AND module_id = ".$db->quote($row["id"], 'integer')." ORDER BY description"); |
||||||||||
213 | 2 | if (PEAR::isError($result_sub)) { |
||||||||||
214 | throw new Exception($result_sub->getUserInfo()); |
|||||||||||
215 | } |
|||||||||||
216 | ||||||||||||
217 | 2 | while ($row_sub = $result_sub->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
||||||||||
218 | 2 | $modules[$i]['sub_access'][$j]['id'] = $row_sub['id']; |
||||||||||
219 | 2 | $modules[$i]['sub_access'][$j]['description'] = $row_sub['description']; |
||||||||||
220 | 2 | $j++; |
||||||||||
221 | 2 | } |
||||||||||
222 | ||||||||||||
223 | 2 | $i++; |
||||||||||
224 | 2 | } |
||||||||||
225 | 2 | return $modules; |
||||||||||
226 | } |
|||||||||||
227 | ||||||||||||
228 | /** |
|||||||||||
229 | * Function to check whether the module has been registered |
|||||||||||
230 | * Made temporarily for /main/index.php |
|||||||||||
231 | */ |
|||||||||||
232 | public static function exists($db, $module_id) |
|||||||||||
233 | { |
|||||||||||
234 | if (is_numeric($module_id)) { |
|||||||||||
235 | throw new Exception("Not yet implemented!"); |
|||||||||||
236 | } else { |
|||||||||||
237 | $result = $db->query('SELECT id FROM module WHERE name = '.$db->quote($module_id, 'text')); |
|||||||||||
238 | if (PEAR::isError($result)) { |
|||||||||||
239 | throw new Exception('Error in query: '.$result->getUserInfo()); |
|||||||||||
240 | } |
|||||||||||
241 | ||||||||||||
242 | if ($result->numRows() > 0) { |
|||||||||||
243 | return true; |
|||||||||||
244 | } else { |
|||||||||||
245 | return false; |
|||||||||||
246 | } |
|||||||||||
247 | } |
|||||||||||
248 | return false; |
|||||||||||
0 ignored issues
–
show
return false; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
||||||||||||
249 | } |
|||||||||||
250 | ||||||||||||
251 | 92 | private static function isValidModuleName($name) |
||||||||||
252 | { |
|||||||||||
253 | 92 | return preg_match("/^[a-z0-9]+$/", $name); |
||||||||||
254 | } |
|||||||||||
255 | } |
|||||||||||
256 |
This check marks private properties in classes that are never used. Those properties can be removed.