Skip to content

Commit d4274a7

Browse files
MyvTsvRom1-B
authored andcommitted
phpstan
1 parent 8a4821f commit d4274a7

11 files changed

Lines changed: 76 additions & 21 deletions

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"require-dev": {
77
"friendsofphp/php-cs-fixer": "^3.85",
8+
"glpi-project/phpstan-glpi": "^1.0",
89
"glpi-project/tools": "^0.7",
910
"php-parallel-lint/php-parallel-lint": "^1.4",
1011
"phpstan/extension-installer": "^1.4",

composer.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/common.class.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,11 @@ public function showGraph($opt, $export = false, $forceFormat = null)
670670
$classname = 'PluginMreporting' . $opt['short_classname'];
671671

672672
//dynamic call of method passed by 'f_name' GET parameter with previously instancied class
673-
$obj = new $classname($config);
673+
if (!is_a($classname, PluginMreportingBaseclass::class, true)) {
674+
return false;
675+
}
676+
$obj = new $classname($config);
677+
674678
$datas = $obj->{$opt['f_name']}($config);
675679

676680
//show graph (pgrah type determined by first entry of explode of camelcase of function name
@@ -1124,6 +1128,9 @@ public function export($opt)
11241128
//dynamic instanciation of class passed by 'short_classname' GET parameter
11251129
$config = PluginMreportingConfig::initConfigParams($func['function'], $classname);
11261130
$class = 'PluginMreporting' . $func['short_classname'];
1131+
if (!is_a($class, PluginMreportingBaseclass::class, true)) {
1132+
return false;
1133+
}
11271134
$obj = new $class($config);
11281135
$randname = $classname . $func['function'];
11291136
if (isset($opt['date1']) && isset($opt['date2'])) {
@@ -1206,6 +1213,9 @@ public function export($opt)
12061213

12071214
//dynamic instanciation of class passed by 'short_classname' GET parameter
12081215
$classname = 'PluginMreporting' . $opt['short_classname'];
1216+
if (!is_a($classname, PluginMreportingBaseclass::class, true)) {
1217+
return false;
1218+
}
12091219
$obj = new $classname($config);
12101220

12111221
//dynamic call of method passed by 'f_name' GET parameter with previously instancied class

inc/config.class.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
if (!defined('GLPI_ROOT')) {
32-
die("Sorry. You can't access directly to this file");
32+
throw new \Glpi\Exception\Http\NotFoundHttpException("Sorry. You can't access directly to this file");
3333
}
3434

3535
class PluginMreportingConfig extends CommonDBTM
@@ -290,6 +290,9 @@ public function createFirstConfig()
290290
foreach ($functions as $funct_name) {
291291
if ($funct_name == 'preconfig') { // If a preconfig exists we construct the class
292292
$classConfig = true;
293+
if (!is_a($classname, PluginMreportingBaseclass::class, true)) {
294+
return;
295+
}
293296
$classObject = new $classname([]);
294297
}
295298
}
@@ -583,7 +586,7 @@ public function prepareInputForAdd($input)
583586

584587
public function prepareInputForUpdate($input)
585588
{
586-
if (isset($input['classname']) && method_exists(new $input['classname']([]), 'checkConfig')) {
589+
if (isset($input['classname']) && is_a($input['classname'], PluginMreportingBaseclass::class, true) && method_exists(new $input['classname']([]), 'checkConfig')) {
587590
$object = new $input['classname']([]);
588591
$checkConfig = $object->checkConfig($input);
589592
if (!$checkConfig['result']) {

inc/graph.class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ public function initGraph($options)
100100

101101
$config = PluginMreportingConfig::initConfigParams($functionname, $classname);
102102

103-
// We check if a configuration is needed for the graph
104-
if (method_exists(new $classname($config), 'needConfig')) {
105-
$object = new $classname();
106-
$object->needConfig($config);
107-
}
108103
}
109104
}
110105

inc/helpdeskplus.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use \Glpi\DBAL\QuerySubQuery;
3434

3535
if (!defined('GLPI_ROOT')) {
36-
die("Sorry. You can't access directly to this file");
36+
throw new \Glpi\Exception\Http\NotFoundHttpException("Sorry. You can't access directly to this file");
3737
}
3838

3939
class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass

inc/notificationevent.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
if (!defined('GLPI_ROOT')) {
32-
die("Sorry. You can't access directly to this file");
32+
throw new \Glpi\Exception\Http\NotFoundHttpException("Sorry. You can't access directly to this file");
3333
}
3434

3535
/**

inc/notificationmail.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
if (!defined('GLPI_ROOT')) {
32-
die("Sorry. You can't access directly to this file");
32+
throw new \Glpi\Exception\Http\NotFoundHttpException("Sorry. You can't access directly to this file");
3333
}
3434

3535
/**

inc/pdf.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
if (!defined('GLPI_ROOT')) {
32-
die("Sorry. You can't access directly to this file");
32+
throw new \Glpi\Exception\Http\NotFoundHttpException("Sorry. You can't access directly to this file");
3333
}
3434

3535
class PluginMreportingPdf extends TCPDF

inc/profile.class.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030

3131
if (!defined('GLPI_ROOT')) {
32-
die("Sorry. You can't access directly to this file");
32+
throw new \Glpi\Exception\Http\NotFoundHttpException("Sorry. You can't access directly to this file");
3333
}
3434

3535
class PluginMreportingProfile extends CommonDBTM
@@ -184,14 +184,16 @@ public static function addRightToProfile($idProfile)
184184
foreach ($config->find() as $report) {
185185
// add right for any reports for profile
186186
// Add manual request because Add function get error : right is set to NULL
187-
$DB->updateOrInsert('glpi_plugin_mreporting_profiles', [
187+
if (!$DB->updateOrInsert('glpi_plugin_mreporting_profiles', [
188188
'profiles_id' => $idProfile,
189189
'reports' => $report['id'],
190190
'right' => READ,
191191
], [
192192
'profiles_id' => $idProfile,
193193
'reports' => $report['id'],
194-
]) or die('An error occurs during profile initialisation.');
194+
])) {
195+
return;
196+
}
195197
}
196198
}
197199

0 commit comments

Comments
 (0)