Skip to content

Commit

Permalink
Code quality fixes; may fix some bugs (#423)
Browse files Browse the repository at this point in the history
* No need to keep that old PHP version support

* Few phpstan fixes

* Method seems no longer used, and call non existant Stat::showGraph()

* Fix duplicated array key

* Always exists, never null

* No "fields" here

* Unsure fixes

* Fix iterator migration

* Fix static call on non static method

* Fix AND query

* Fix polymorphic methods calls

* Fix phpstan issues

Those may be bugs, but fix will not change that.

* Run phpstan

* Update inc/profile.class.php

Co-authored-by: Cédric Anne <[email protected]>

---------

Co-authored-by: Cédric Anne <[email protected]>
  • Loading branch information
trasher and cedric-anne authored Oct 19, 2023
1 parent 94e6216 commit 59dbb29
Show file tree
Hide file tree
Showing 31 changed files with 830 additions and 820 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@ jobs:
run: cd glpi && php bin/console glpi:plugin:activate -n --ansi --config-dir=tests/config glpiinventory
- name: run tests
run: cd glpi/plugins/glpiinventory/ && php vendor/bin/phpunit --testdox --colors=always tests/
- name: PHPStan checks
run: cd glpi/plugins/glpiinventory && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
},
"require-dev": {
"glpi-project/tools": "^0.6",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
},
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.

4 changes: 1 addition & 3 deletions inc/collect.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ public function prepareRun($taskjobs_id)
]);
$row = $iterator->current();

if (isset($_GET)) {
$get_tmp = $_GET;
}
$get_tmp = $_GET;
if (isset($_SESSION["glpisearchcount"]['Computer'])) {
unset($_SESSION["glpisearchcount"]['Computer']);
}
Expand Down
6 changes: 3 additions & 3 deletions inc/commonview.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ class PluginGlpiinventoryCommonView extends CommonDBTM
/**
* Define the number for the message information constant
*
* @var interger
* @var integer
*/
const MSG_INFO = 0;

/**
* Define the number for the message warning constant
*
* @var interger
* @var integer
*/
const MSG_WARNING = 1;

/**
* Define the number for the message error constant
*
* @var interger
* @var integer
*/
const MSG_ERROR = 2;

Expand Down
1 change: 1 addition & 0 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function rawSearchOptions()
'id' => 'fields_plugin',
'name' => __('Plugin fields')
];
/** @phpstan-ignore-next-line */
$fieldsoptions = plugin_fields_getAddSearchOptions('Computer');
foreach ($fieldsoptions as $id => $data) {
$data['id'] = $id;
Expand Down
2 changes: 2 additions & 0 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ public static function getActions($action)
case self::ACTION_CLEAN:
return __('Clean agents', 'glpiinventory');
}

return '';
}


Expand Down
13 changes: 8 additions & 5 deletions inc/deployaction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public function displayList(PluginGlpiinventoryDeployPackage $package, $data, $r
* @param array $config
* @param array $request_data
* @param string $mode mode in use (create, edit...)
* @return boolean
* @return void
*/
public function displayAjaxValues($config, $request_data, $rand, $mode)
{
Expand Down Expand Up @@ -292,11 +292,9 @@ public function displayAjaxValues($config, $request_data, $rand, $mode)
$value_type_1 = "input";
$value_1 = "";
$value_2 = "";
$name_label_2 = "";
$retChecks = null;
$name_label = __('Action label', 'glpiinventory');
$name_value = (isset($config_data['name'])) ? $config_data['name'] : "";
$name_type = "input";
$logLineLimit = (isset($config_data['logLineLimit'])) ? $config_data['logLineLimit'] : 100;

/*
* set values from element's config in 'edit' mode
Expand All @@ -309,7 +307,9 @@ public function displayAjaxValues($config, $request_data, $rand, $mode)
$value_label_2 = __("To", 'glpiinventory');
$name_label_2 = "to";
if ($mode === self::EDIT) {
/** @phpstan-ignore-next-line */
$value_1 = $config_data['from'];
/** @phpstan-ignore-next-line */
$value_2 = $config_data['to'];
}
break;
Expand All @@ -320,6 +320,7 @@ public function displayAjaxValues($config, $request_data, $rand, $mode)
$value_label_2 = false;
$value_type_1 = "textarea";
if ($mode === self::EDIT) {
/** @phpstan-ignore-next-line */
$value_1 = $config_data['exec'];
if (isset($config_data['retChecks'])) {
$retChecks = $config_data['retChecks'];
Expand All @@ -337,6 +338,7 @@ public function displayAjaxValues($config, $request_data, $rand, $mode)
* TODO : Add list input like `retChecks` on `mkdir` and `delete`
* because those methods are defined as list in specification
*/
/** @phpstan-ignore-next-line */
$value_1 = array_shift($config_data['list']);
}
break;
Expand Down Expand Up @@ -463,8 +465,9 @@ function removeLine(item) {
*/
public function add_item($params)
{
//prepare new action entry to insert in json
//prepare new action entry to insert in json
$fields = ['list', 'from', 'to', 'exec', 'name', 'logLineLimit'];
$tmp = [];
foreach ($fields as $field) {
if (isset($params[$field])) {
$tmp[$field] = $params[$field];
Expand Down
12 changes: 6 additions & 6 deletions inc/deploycheck.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public function getLabelsAndTypes($check_type, $mandatory = false)
* @param array $request_data
* @param string $rand unique element id used to identify/update an element
* @param string $mode mode in use (create, edit...)
* @return boolean
* @return void
*/
public function displayAjaxValues($config, $request_data, $rand, $mode)
{
Expand Down Expand Up @@ -603,10 +603,10 @@ public function getValueForReturn($value)

/**
* Return an array corresponding to a check, ready to be serialized
* @param params the check's parameters
* @param $params the check's parameters
* @return array the array to be encoded in json and serialized
*/
public static function formatCheckForJson($params)
public function formatCheckForJson($params)
{
if (!isset($params['value'])) {
$params['value'] = "";
Expand All @@ -622,7 +622,7 @@ public static function formatCheckForJson($params)
if ($params['checkstype'] == "freespaceGreater") {
$params['value'] = $params['value'] / (1024 * 1024);
} else {
$params['value'] = $params['value'] * self::getUnitSize($params['unit']);
$params['value'] = $params['value'] * $this->getUnitSize($params['unit']);
}
}
}
Expand All @@ -647,7 +647,7 @@ public static function formatCheckForJson($params)
*/
public function add_item($params)
{
$entry = self::formatCheckForJson($params);
$entry = $this->formatCheckForJson($params);

//get current order json
$datas = json_decode(
Expand All @@ -670,7 +670,7 @@ public function add_item($params)
*/
public function save_item($params)
{
$entry = self::formatCheckForJson($params);
$entry = $this->formatCheckForJson($params);
//get current order json
$datas = json_decode($this->getJson($params['id']), true);

Expand Down
4 changes: 1 addition & 3 deletions inc/deploycommon.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ public function prepareRun($taskjob_id, $definitions_filter = null)
}
$row = $iterator->current();

if (isset($_GET)) {
$get_tmp = $_GET;
}
$get_tmp = $_GET;
if (isset($_SESSION["glpisearchcount"]['Computer'])) {
unset($_SESSION["glpisearchcount"]['Computer']);
}
Expand Down
Loading

0 comments on commit 59dbb29

Please sign in to comment.