Skip to content

Commit

Permalink
Feature/ci (#9)
Browse files Browse the repository at this point in the history
* phpstan lvl 1

* Some lvl 2 fixes; but cannot force since all is not fixed

* Update CI config

* Check also setup

* phpstan lvl 2

* phpstan lvl 3

* phpstan lvl 4 fixes, not enforced

* Fix withtemplate

* improve phpdoc
  • Loading branch information
trasher authored Nov 14, 2023
1 parent 877ea79 commit 47fc06f
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 114 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
80 changes: 73 additions & 7 deletions composer.lock

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

13 changes: 7 additions & 6 deletions front/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

include("../../../inc/includes.php");

/** @var array $CFG_GLPI */
global $CFG_GLPI;

Html::header(
__('Database Inventory', 'databaseinventory'),
$_SERVER['PHP_SELF'],
Expand All @@ -42,12 +45,10 @@
echo "<table class='tab_cadre'>";
echo "<tr><th colspan='2'>" . __('Database Inventory', 'databaseinventory') . "</th></tr>";

if (PluginDatabaseinventoryDatabaseParam::canView()) {
echo "<tr class='tab_bg_1 center'>";
echo "<td><i class='fas fa-cog'></i></td>";
echo "<td><a href='" . Toolbox::getItemTypeSearchURL('PluginDatabaseinventoryDatabaseParam') . "'>"
. PluginDatabaseinventoryDatabaseParam::getTypeName(2) . "</a></td></tr>";
}
echo "<tr class='tab_bg_1 center'>";
echo "<td><i class='fas fa-cog'></i></td>";
echo "<td><a href='" . Toolbox::getItemTypeSearchURL('PluginDatabaseinventoryDatabaseParam') . "'>"
. PluginDatabaseinventoryDatabaseParam::getTypeName(2) . "</a></td></tr>";

if (PluginDatabaseinventoryCredential::canView()) {
echo "<tr class='tab_bg_1 center'>";
Expand Down
6 changes: 4 additions & 2 deletions inc/computergroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public function showForm($ID, array $options = [])
$this->initForm($ID, $options);
$this->showFormHeader($options);

$rand = mt_rand();
echo "<tr><td><label for='textfield_name$rand'>" . __('Name') . "</label></td>";
echo "<td>";
echo Html::input(
Expand All @@ -169,6 +168,7 @@ public function showForm($ID, array $options = [])

public function countDynamicItem()
{
/** @var DBmysql $DB */
global $DB;
$count = 0;

Expand All @@ -192,8 +192,8 @@ public function countDynamicItem()

public function countStaticItem()
{
/** @var DBmysql $DB */
global $DB;
$count = 0;

$params = [
'SELECT' => '*',
Expand All @@ -209,6 +209,7 @@ public function countStaticItem()

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down Expand Up @@ -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)) {
Expand Down
12 changes: 5 additions & 7 deletions inc/computergroupdynamic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 '';
}
Expand All @@ -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 = " ";
Expand Down Expand Up @@ -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);
Expand All @@ -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'][] = [
Expand Down Expand Up @@ -248,6 +244,7 @@ function() {

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand All @@ -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)) {
Expand Down
13 changes: 7 additions & 6 deletions inc/computergroupstatic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand All @@ -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');
Expand All @@ -108,9 +106,10 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput
}
$number = count($datas);

$rand = mt_rand();

echo "<div class='spaced'>";
if ($computergroup->canAddItem('itemtype')) {
$rand = mt_rand();
echo "<div class='firstbloc'>";
echo "<form method='post' name='staticcomputer_form$rand'
id='staticcomputer$rand'
Expand Down Expand Up @@ -227,6 +226,7 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand All @@ -252,6 +252,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)) {
Expand Down
Loading

0 comments on commit 47fc06f

Please sign in to comment.