Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpstan lvl 1 #723

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ajax/reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
$old_order = (int)$_POST['old_order'];
$new_order = (int)$_POST['new_order'];

/** @var DBmysql $DB */
global $DB;

// Retrieve id of field to update
$field_iterator = $DB->request(
[
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require-dev": {
"glpi-project/tools": "^0.6",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1.10",
"squizlabs/php_codesniffer": "^3.6"
},
"config": {
Expand Down
66 changes: 64 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion front/commondropdown.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

include "../../../inc/includes.php";
if (preg_match('/[a-z]/i', $_REQUEST['ddtype']) !== 1) {
throw new \RuntimeException(sprintf('Invalid itemtype "%"', $_REQUEST['ddtype']));
throw new \RuntimeException(sprintf('Invalid itemtype "%1$s"', $_REQUEST['ddtype']));
}
$path = PLUGINFIELDS_FRONT_PATH . '/' . $_REQUEST['ddtype'] . '.form.php';
require_once $path;
2 changes: 1 addition & 1 deletion front/commondropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

include "../../../inc/includes.php";
if (preg_match('/[a-z]/i', $_REQUEST['ddtype']) !== 1) {
throw new \RuntimeException(sprintf('Invalid itemtype "%"', $_REQUEST['ddtype']));
throw new \RuntimeException(sprintf('Invalid itemtype "%1$s"', $_REQUEST['ddtype']));
}
$path = PLUGINFIELDS_FRONT_PATH . '/' . $_REQUEST['ddtype'] . '.php';
require_once $path;
1 change: 1 addition & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function plugin_fields_rule_matched($params = [])

switch ($params['sub_type']) {
case "PluginFusioninventoryTaskpostactionRule":
/** @phpstan-ignore-next-line */
$agent = new PluginFusioninventoryAgent();

if (isset($params['input']['plugin_fusioninventory_agents_id'])) {
Expand Down
12 changes: 11 additions & 1 deletion inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ public static function getSpecificValueToDisplay($field, $values, array $options
}
return $obj;
}

return '';
}


Expand All @@ -487,7 +489,7 @@ public function getValueToSelect($field_id_or_search_options, $name = '', $value
return Dropdown::showFromArray($name, self::getTypes(), $options);
case $this->getTable() . '.itemtypes':
$options['display'] = false;
return Dropdown::showFromArray($name, self::getItemtypes(), $options);
return Dropdown::showFromArray($name, self::getItemtypes(false), $options);
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
}

return parent::getValueToSelect($field_id_or_search_options, $name, $values, $options);
Expand Down Expand Up @@ -1114,6 +1116,8 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
}
return $tabs_entries;
}

return '';
}


Expand All @@ -1133,6 +1137,8 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
return PluginFieldsField::showForTabContainer($data['id'], $item);
}
}

return true;
}

/**
Expand Down Expand Up @@ -1576,6 +1582,8 @@ public static function postItemAdd(CommonDBTM $item)
}
return $item->input = [];
}

return true;
}

/**
Expand All @@ -1601,6 +1609,8 @@ public static function preItemUpdate(CommonDBTM $item)
}
return $item->input = [];
}

return true;
}


Expand Down
8 changes: 6 additions & 2 deletions inc/containerdisplaycondition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ private static function getItemtypesForContainer(int $container_id): array
{
global $DB;

$results = [];

$iterator = $DB->request([
'SELECT' => ['itemtypes'],
'FROM' => PluginFieldsContainer::getTable(),
Expand All @@ -212,9 +214,9 @@ private static function getItemtypesForContainer(int $container_id): array
foreach ($itemtypes as $itemtype) {
$results[$itemtype] = $itemtype::getTypeName();
}
return $results;
}
return [];

return $results;
}


Expand Down Expand Up @@ -551,6 +553,8 @@ public function showForm($ID, array $options = [])
: self::removeBlackListedOption(Search::getOptions($this->fields['itemtype']), $this->fields['itemtype']),
];
TemplateRenderer::getInstance()->display('@fields/forms/container_display_condition.html.twig', $twig_params);

return true;
}

public function getCloneRelations(): array
Expand Down
8 changes: 5 additions & 3 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function prepareInputForAdd($input)

//reject adding for same dropdown on same bloc
if (!empty($found)) {
Session::AddMessageAfterRedirect(__("You cannot add same field 'dropdown' on same bloc", 'fields', false, ERROR));
Session::AddMessageAfterRedirect(__("You cannot add same field 'dropdown' on same bloc", 'fields'), false, ERROR);
return false;
}

Expand Down Expand Up @@ -676,8 +676,8 @@ public function showForm($ID, $options = [])
{
$rand = mt_rand();

$container = new PluginFieldsContainer();
if (isset($options['parent_id']) && !empty($options['parent_id'])) {
$container = new PluginFieldsContainer();
$container->getFromDB($options['parent_id']);
} else if (
isset($options['parent'])
Expand All @@ -697,7 +697,7 @@ public function showForm($ID, $options = [])
}

$this->initForm($ID, $options);
$this->showFormHeader($ID, $options);
$this->showFormHeader($options);

echo "<tr>";
echo "<td>" . __("Label") . " : </td>";
Expand Down Expand Up @@ -774,6 +774,8 @@ public function showForm($ID, $options = [])
echo "</tr>";

$this->showFormButtons($options);

return true;
}

public static function showForTabContainer($c_id, $item)
Expand Down
6 changes: 5 additions & 1 deletion inc/inventory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public static function updateInventory($params = [])
$availaibleItemType = ["Computer","Printer","NetworkEquipment"];
foreach (array_keys($params['inventory_data']) as $itemtype) {
if (in_array($itemtype, $availaibleItemType)) {
//retrive items id switch itemtype
$items_id = 0;
//retrieve items id switch itemtype
switch ($itemtype) {
case Computer::getType():
$items_id = $params['computers_id'];
Expand All @@ -57,6 +58,7 @@ public static function updateInventory($params = [])
if ($itemtype == Computer::getType()) {
//load inventory from DB because
//FI not update XML file if computer is not update
/** @phpstan-ignore-next-line */
$db_info = new PluginFusioninventoryInventoryComputerComputer();
if ($db_info->getFromDBByCrit(['computers_id' => $items_id])) {
$arrayinventory = unserialize(gzuncompress($db_info->fields['serialized_inventory']));
Expand All @@ -68,6 +70,7 @@ public static function updateInventory($params = [])
//Load XML file because FI always update XML file and don't store inventory into DB
$file = self::loadXMLFile($itemtype, $items_id);
if ($file !== false) {
/** @phpstan-ignore-next-line */
$arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file);
if (isset($arrayinventory['CUSTOM'])) {
self::updateFields($arrayinventory['CUSTOM']['CONTAINER'], $itemtype, $items_id);
Expand Down Expand Up @@ -108,6 +111,7 @@ public static function loadXMLFile($itemtype, $items_id)
}

//Check if the file exists with the .xml extension (new format)
/** @phpstan-ignore-next-line */
$file = PLUGIN_FUSIONINVENTORY_XML_DIR . strtolower($itemtype) . "/" . $folder . "/" . $items_id;
if (file_exists($file . '.xml')) {
$file .= '.xml';
Expand Down
1 change: 1 addition & 0 deletions inc/labeltranslation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
self::showTranslations($item);
return true;
}

/**
Expand Down
1 change: 1 addition & 0 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
echo "</tr>";
echo "</table></div>";
Html::closeForm();
return true;
}

public static function updateProfile($input)
Expand Down
1 change: 1 addition & 0 deletions inc/statusoverride.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,6 @@ public function showForm($ID, array $options = [])
'container_fields' => self::getFieldsChoiceForContainer($container_id),
];
TemplateRenderer::getInstance()->display('@fields/forms/status_override.html.twig', $twig_params);
return true;
}
}
1 change: 1 addition & 0 deletions inc/toolbox.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public static function getGlpiItemtypes(): array
$plugin = new Plugin();
if ($plugin->isActivated('genericobject') && method_exists('PluginGenericobjectType', 'getTypes')) {
$go_itemtypes = [];
/** @phpstan-ignore-next-line */
foreach (array_keys(PluginGenericobjectType::getTypes()) as $go_itemtype) {
if (!class_exists($go_itemtype)) {
continue;
Expand Down
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 1
bootstrapFiles:
- ../../inc/based_config.php
- setup.php
trasher marked this conversation as resolved.
Show resolved Hide resolved
paths:
- inc
- front
- ajax
- hook.php
scanDirectories:
- ../../inc
- ../../src
stubFiles:
- ../../stubs/glpi_constants.php
trasher marked this conversation as resolved.
Show resolved Hide resolved