Skip to content

Commit

Permalink
Fix phpstan level 5 error
Browse files Browse the repository at this point in the history
  • Loading branch information
Lainow committed Jan 30, 2025
1 parent 0769e1d commit 354196c
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 142 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"php": ">=7.4"
},
"require-dev": {
"glpi-project/tools": "^0.7",
"glpi-project/tools": "^0.7.4",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"squizlabs/php_codesniffer": "^3.9"
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"squizlabs/php_codesniffer": "^3.10"
},
"config": {
"optimize-autoloader": true,
Expand Down
339 changes: 212 additions & 127 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inc/clientinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static function processInjection(PluginDatainjectionModel $model, $entiti
* to be used instead of Toolbox::stripslashes_deep to reduce memory usage
* execute stripslashes in place (no copy)
*
* @param array|null $value array of value
* @param array|string|null $value array of value
*/
public static function stripslashes_array(&$value) // phpcs:ignore
{
Expand Down
8 changes: 4 additions & 4 deletions inc/commoninjectionlib.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private function manageFieldValues()
//searchoption relation type is already manage by manageRelations()
//skip it
if (
$searchOption !== false
!empty($searchOption)
&& ((isset($searchOption['displaytype']) && $searchOption['displaytype'] != 'relation')
|| !isset($searchOption['displaytype']))
) {
Expand Down Expand Up @@ -1575,18 +1575,18 @@ private function effectiveAddOrUpdate($injectionClass, $item, $values, $add = tr

foreach ($values as $key => $value) {
$option = self::findSearchOption($options, $key);
if ($option !== false && isset($option['checktype']) && $option['checktype'] == self::FIELD_VIRTUAL) {
if (!empty($option) && isset($option['checktype']) && $option['checktype'] == self::FIELD_VIRTUAL) {
break;
}

//CommonDBRelation are managed separately, so related field should be ignored
// Ex : User -> groups_id -> Group_User
// groups_id should not be injected in User (field contains group name (string))
if ($option !== false && isset($option['displaytype']) && $option['displaytype'] == 'relation') {
if (!empty($option) && isset($option['displaytype']) && $option['displaytype'] == 'relation') {
continue;
}

if ($option !== false && self::isFieldADropdown($option['displaytype']) && $value == self::EMPTY_VALUE) {
if (!empty($option) && self::isFieldADropdown($option['displaytype']) && $value == self::EMPTY_VALUE) {
//If field is a dropdown and value is '', then replace it by 0
$toinject[$key] = self::DROPDOWN_EMPTY_VALUE;
} else {
Expand Down
2 changes: 1 addition & 1 deletion inc/engine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function addValueToInject(
$return_value = $value;

if (
$option !== false && ($option['displaytype'] == 'multiline_text')
!empty($option) && ($option['displaytype'] == 'multiline_text')
&& in_array($mapping->getValue(), $several)
&& ($value != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE)
) {
Expand Down
4 changes: 2 additions & 2 deletions inc/injectioninterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ public function addOrUpdateObject($values = [], $options = []);
* Add specific values to the object to inject
* This method is optionnal ! Implement it if the itemtype need special reformat
*
* @param primary_type the primary_type to inject
* @param fields_toinject all the fields that need to be injected
* @param string $primary_type the primary_type to inject
* @param array $fields_toinject all the fields that need to be injected
**/
//function addSpecificNeededFields($primary_type, $fields_toinject);
}
2 changes: 1 addition & 1 deletion inc/mappingcollection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function saveAllMappings()

foreach ($this->mappingCollection as $mapping) {
if (isset($mapping->fields["id"])) {
$mapping->update($mapping->fields); /** @phpstan-ignore-line */
$mapping->update($mapping->fields);
} else {
$mapping->fields["id"] = $mapping->add($mapping->fields);
}
Expand Down
2 changes: 1 addition & 1 deletion inc/model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public static function clean($crit = [])

$model = new self();

if (is_array($crit) && (count($crit) > 0)) {
if ((count($crit) > 0)) {
$crit['FIELDS'] = 'id';
foreach ($DB->request($model->getTable(), $crit) as $row) {
$model->delete($row);
Expand Down

0 comments on commit 354196c

Please sign in to comment.