diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..f8093d9 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,31 @@ +name: "Continuous integration" + +on: + push: + branches: + - "main" + tags: + - "*" + pull_request: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + ci: + name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}" + strategy: + fail-fast: false + matrix: + include: + - {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"} + - {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"} + - {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"} + - {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"} + - {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"} + uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1" + with: + plugin-key: "databaseinventory" + glpi-version: "${{ matrix.glpi-version }}" + php-version: "${{ matrix.php-version }}" + db-image: "${{ matrix.db-image }}" diff --git a/composer.json b/composer.json index 9ac6eb9..60223c5 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,9 @@ "php": ">=7.4" }, "require-dev": { - "glpi-project/tools": "^0.6", + "glpi-project/tools": "^0.7.1", "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/phpstan": "^1.10", "squizlabs/php_codesniffer": "^3.7" }, "config": { diff --git a/composer.lock b/composer.lock index 7b680f2..d21a0f2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,27 +4,31 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dcfa1cccfc615cf14840495fef4497bb", + "content-hash": "fc6c417f71dc479b026d089b5d21af9a", "packages": [], "packages-dev": [ { "name": "glpi-project/tools", - "version": "0.6.4", + "version": "0.7.1", "source": { "type": "git", "url": "https://github.com/glpi-project/tools.git", - "reference": "8ef917fa2967e716eaed198bb803f418a80cd621" + "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/glpi-project/tools/zipball/8ef917fa2967e716eaed198bb803f418a80cd621", - "reference": "8ef917fa2967e716eaed198bb803f418a80cd621", + "url": "https://api.github.com/repos/glpi-project/tools/zipball/4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb", + "reference": "4bc5a725d9f4da0ee946ad3cbdd54a782d2f40fb", "shasum": "" }, "require": { "symfony/console": "^5.4 || ^6.0", "twig/twig": "^3.3" }, + "require-dev": { + "nikic/php-parser": "^4.13", + "phpstan/phpstan-src": "^1.10" + }, "bin": [ "bin/extract-locales", "bin/licence-headers-check", @@ -33,7 +37,7 @@ "type": "library", "autoload": { "psr-4": { - "Glpi\\": "src/" + "GlpiProject\\Tools\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -57,7 +61,7 @@ "issues": "https://github.com/glpi-project/tools/issues", "source": "https://github.com/glpi-project/tools" }, - "time": "2023-07-27T12:32:25+00:00" + "time": "2023-10-16T11:40:35+00:00" }, { "name": "php-parallel-lint/php-parallel-lint", @@ -116,6 +120,68 @@ }, "time": "2022-02-21T12:50:22+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.40", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d", + "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-10-30T14:48:31+00:00" + }, { "name": "psr/container", "version": "1.1.2", diff --git a/front/menu.php b/front/menu.php index f0bc239..5fa48b6 100644 --- a/front/menu.php +++ b/front/menu.php @@ -30,6 +30,9 @@ include("../../../inc/includes.php"); +/** @var array $CFG_GLPI */ +global $CFG_GLPI; + Html::header( __('Database Inventory', 'databaseinventory'), $_SERVER['PHP_SELF'], @@ -42,12 +45,10 @@ echo "
" . __('Database Inventory', 'databaseinventory') . " | |
---|---|
"; - echo " | " - . PluginDatabaseinventoryDatabaseParam::getTypeName(2) . " |
"; + echo " | " + . PluginDatabaseinventoryDatabaseParam::getTypeName(2) . " |
"; echo " | ";
echo Html::input(
@@ -169,6 +168,7 @@ public function showForm($ID, array $options = [])
public function countDynamicItem()
{
+ /** @var DBmysql $DB */
global $DB;
$count = 0;
@@ -192,8 +192,8 @@ public function countDynamicItem()
public function countStaticItem()
{
+ /** @var DBmysql $DB */
global $DB;
- $count = 0;
$params = [
'SELECT' => '*',
@@ -209,6 +209,7 @@ public function countStaticItem()
public static function install(Migration $migration)
{
+ /** @var DBmysql $DB */
global $DB;
$default_charset = DBConnection::getDefaultCharset();
@@ -248,6 +249,7 @@ public static function install(Migration $migration)
public static function uninstall(Migration $migration)
{
+ /** @var DBmysql $DB */
global $DB;
$table = self::getTable();
if ($DB->tableExists($table)) {
diff --git a/inc/computergroupdynamic.class.php b/inc/computergroupdynamic.class.php
index 258a042..a0b9fea 100644
--- a/inc/computergroupdynamic.class.php
+++ b/inc/computergroupdynamic.class.php
@@ -49,7 +49,7 @@ public static function canPurge()
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
- if (get_class($item) == PluginDatabaseinventoryComputerGroup::getType()) {
+ if ($item instanceof PluginDatabaseinventoryComputerGroup) {
$count = 0;
$computergroup_dynamic = new self();
if (
@@ -59,9 +59,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
) {
$count = $computergroup_dynamic->countDynamicItems();
}
- $ong = [];
- $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count);
- return $ong;
+ return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count);
}
return '';
}
@@ -82,6 +80,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
return ($count) ? $count : ' 0 ';
case '_virtual_dynamic_list':
+ /** @var array $CFG_GLPI */
global $CFG_GLPI;
$value = " ";
$out = " ";
@@ -149,7 +148,6 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
private function countDynamicItems()
{
- $count = 0;
$search_params = Search::manageParams('Computer', unserialize($this->fields['search']));
$data = Search::prepareDatasForSearch('Computer', $search_params);
Search::constructSQL($data);
@@ -160,8 +158,6 @@ private function countDynamicItems()
public function isDynamicSearchMatchComputer(Computer $computer)
{
- $count = 0;
-
// add new criteria to force computer ID
$search = unserialize($this->fields['search']);
$search['criteria'][] = [
@@ -248,6 +244,7 @@ function() {
public static function install(Migration $migration)
{
+ /** @var DBmysql $DB */
global $DB;
$default_charset = DBConnection::getDefaultCharset();
@@ -272,6 +269,7 @@ public static function install(Migration $migration)
public static function uninstall(Migration $migration)
{
+ /** @var DBmysql $DB */
global $DB;
$table = self::getTable();
if ($DB->tableExists($table)) {
diff --git a/inc/computergroupstatic.class.php b/inc/computergroupstatic.class.php
index 32e9ae2..b00fcd6 100644
--- a/inc/computergroupstatic.class.php
+++ b/inc/computergroupstatic.class.php
@@ -64,12 +64,9 @@ public static function canPurge()
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
- if (get_class($item) == PluginDatabaseinventoryComputerGroup::getType()) {
- $count = 0;
+ if ($item instanceof PluginDatabaseinventoryComputerGroup) {
$count = countElementsInTable(self::getTable(), ['plugin_databaseinventory_computergroups_id' => $item->getID()]);
- $ong = [];
- $ong[1] = self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count);
- return $ong;
+ return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $count);
}
return '';
}
@@ -86,6 +83,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
private static function showForItem(PluginDatabaseinventoryComputerGroup $computergroup)
{
+ /** @var DBmysql $DB */
global $DB;
$ID = $computergroup->getField('id');
@@ -108,9 +106,10 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput
}
$number = count($datas);
+ $rand = mt_rand();
+
echo " ";
if ($computergroup->canAddItem('itemtype')) {
- $rand = mt_rand();
echo " ";
echo " |