Skip to content

Commit

Permalink
phpstan lvl 0
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Oct 30, 2023
1 parent bfb97f8 commit a1e4395
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 12 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
matrix:
include:
- {php-version: "7.4"}
- {php-version: "8.0"}
- {php-version: "8.1"}
- {php-version: "8.2"}
- {php-version: "8.3-rc"}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
Expand All @@ -28,15 +32,6 @@ jobs:
php-version: "${{ matrix.php-version }}"
coverage: "none"
tools: "composer, cs2pr"
- name: "Get Composer cache directory"
id: "composer-cache"
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: "Restore dependencies cache"
uses: "actions/cache@v3"
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}"
- name: "Install Composer dependencies"
run: |
composer install --ansi --no-interaction --no-progress --prefer-dist
Expand All @@ -49,3 +44,18 @@ jobs:
- name: "Check for missing/outdated headers"
run: |
vendor/bin/licence-headers-check --ansi --no-interaction
- name: Checkout GLPI
uses: actions/checkout@v4
with:
repository: glpi-project/glpi
path: glpi
fetch-depth: 1
ref: 10.0/bugfixes
- name: Install xmllint
run: sudo apt-get install -y gettext
- name: "Build dependencies / translations"
run: cd glpi && php bin/console dependencies install && php bin/console locales:compile
- name: Copy plugin
run: rsync -avr --exclude='glpi' ./* glpi/plugins/fields/
- name: PHPStan checks
run: cd glpi/plugins/fields && 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 @@ -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.

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);
}

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
2 changes: 2 additions & 0 deletions inc/containerdisplaycondition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,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
2 changes: 2 additions & 0 deletions inc/field.class.php
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions inc/inventory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 +69,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
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
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 0
bootstrapFiles:
- ../../inc/based_config.php
- setup.php
paths:
- inc
scanDirectories:
- ../../inc
- ../../src
stubFiles:
- ../../stubs/glpi_constants.php

0 comments on commit a1e4395

Please sign in to comment.