Skip to content

Commit c2cf384

Browse files
authored
Feat(CI): standardize CI conf (#87)
* Feat(CI): standardize CI conf * fix
1 parent 8ca8f25 commit c2cf384

22 files changed

+188
-205
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist/
22
vendor/
33
.gh_token
44
*.min.*
5+
var/

.php-cs-fixer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55

66
$finder = Finder::create()
77
->in(__DIR__)
8-
->name('*.php');
8+
->name('*.php')
9+
->ignoreVCSIgnored(true);
910

1011
$config = new Config();
1112

1213
$rules = [
13-
'@PER-CS2.0' => true,
14-
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
14+
'@PER-CS' => true, // Latest PER rules.
1515
];
1616

1717
return $config
1818
->setRules($rules)
1919
->setFinder($finder)
20-
->setUsingCache(false);
20+
->setCacheFile(__DIR__ . '/var/php-cs-fixer/.php-cs-fixer.cache')
21+
;

ajax/agent.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@
4545
$agent = new Agent();
4646
if (!$agent->getFromDB($_POST['id'])) {
4747
throw new NotFoundHttpException();
48-
};
48+
}
49+
4950
$answer = [];
5051

51-
switch ($_POST['action']) {
52-
case PluginDatabaseinventoryInventoryAction::MA_PARTIAL:
53-
$answer = PluginDatabaseinventoryInventoryAction::runPartialInventory($agent);
54-
break;
52+
if ($_POST['action'] === PluginDatabaseinventoryInventoryAction::MA_PARTIAL) {
53+
$answer = PluginDatabaseinventoryInventoryAction::runPartialInventory($agent);
5554
}
5655

5756
echo json_encode($answer);

composer.lock

Lines changed: 10 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/computergroup.form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
Html::redirect($computergroup->getLinkURL());
6060
}
6161
}
62+
6263
Html::back();
6364
} elseif (isset($_POST['add_staticcomputer'])) {
6465
if (!$_POST['computers_id']) {
@@ -81,6 +82,7 @@
8182
Html::redirect($computergroup->getLinkURL());
8283
}
8384
}
85+
8486
Html::back();
8587
} elseif (isset($_POST['purge'])) {
8688
// purge a computergroup
@@ -95,6 +97,7 @@
9597
sprintf(__s('%s purges an item'), $_SESSION['glpiname']),
9698
);
9799
}
100+
98101
$computergroup->redirectToList();
99102
} elseif (isset($_POST['update'])) {
100103
// update a computergroup
@@ -143,5 +146,6 @@
143146
} else {
144147
$computergroup->display($_GET);
145148
}
149+
146150
Html::footer();
147151
}

front/credential.form.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
Html::redirect($credential->getLinkURL());
5959
}
6060
}
61+
6162
Html::back();
6263
} elseif (isset($_POST['purge'])) {
6364
// purge a credential
@@ -72,6 +73,7 @@
7273
sprintf(__s('%s purges an item'), $_SESSION['glpiname']),
7374
);
7475
}
76+
7577
$credential->redirectToList();
7678
} elseif (isset($_POST['update'])) {
7779
// update a credential
@@ -95,5 +97,6 @@
9597
} else {
9698
$credential->display($_GET);
9799
}
100+
98101
Html::footer();
99102
}

front/databaseparam.form.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
Html::redirect($databaseparam->getLinkURL());
6161
}
6262
}
63+
6364
Html::back();
6465
} elseif (isset($_POST['add_credential'])) {
6566
// add credential
@@ -78,6 +79,7 @@
7879
Html::redirect($databaseparam->getLinkURL());
7980
}
8081
}
82+
8183
Html::back();
8284
} elseif (isset($_POST['add_computergroup'])) {
8385
// add computer group
@@ -96,6 +98,7 @@
9698
Html::redirect($databaseparam->getLinkURL());
9799
}
98100
}
101+
99102
Html::back();
100103
} elseif (isset($_POST['purge'])) {
101104
// purge a databaseparam
@@ -110,6 +113,7 @@
110113
sprintf(__s('%s purges an item'), $_SESSION['glpiname']),
111114
);
112115
}
116+
113117
$databaseparam->redirectToList();
114118
} elseif (isset($_POST['update'])) {
115119
// update a databaseparam
@@ -133,5 +137,6 @@
133137
} else {
134138
$databaseparam->display($_GET);
135139
}
140+
136141
Html::footer();
137142
}

hook.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function plugin_databaseinventory_install()
5353
}
5454
}
5555
}
56+
5657
$migration->executeMigration();
5758

5859
return true;
@@ -79,6 +80,7 @@ function plugin_databaseinventory_uninstall()
7980
}
8081
}
8182
}
83+
8284
$migration->executeMigration();
8385

8486
return true;

inc/computergroup.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
class PluginDatabaseinventoryComputerGroup extends CommonDBTM
6262
{
6363
public $dohistory = true;
64+
6465
public static $rightname = 'database_inventory';
6566

6667
public static function getTypeName($nb = 0)
@@ -220,9 +221,8 @@ public function countStaticItem()
220221
];
221222

222223
$iterator = $DB->request($params);
223-
$count = count($iterator);
224224

225-
return $count;
225+
return count($iterator);
226226
}
227227

228228
public static function install(Migration $migration)
@@ -236,9 +236,9 @@ public static function install(Migration $migration)
236236

237237
$table = self::getTable();
238238
if (!$DB->tableExists($table)) {
239-
$migration->displayMessage("Installing $table");
239+
$migration->displayMessage('Installing ' . $table);
240240
$query = <<<SQL
241-
CREATE TABLE IF NOT EXISTS `$table` (
241+
CREATE TABLE IF NOT EXISTS `{$table}` (
242242
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
243243
`name` varchar(255) DEFAULT NULL,
244244
`comment` text,

inc/computergroupdynamic.class.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
7575
if (!is_array($values)) {
7676
$values = [$field => $values];
7777
}
78+
7879
switch ($field) {
7980
case 'search':
8081
$count = 0;
@@ -91,7 +92,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
9192
global $CFG_GLPI;
9293
$value = ' ';
9394
$out = ' ';
94-
if (!str_contains($values['id'], Search::NULLVALUE)) {
95+
if (!str_contains((string) $values['id'], Search::NULLVALUE)) {
9596
$search_params = Search::manageParams('Computer', unserialize($values['search']));
9697
$data = Search::prepareDatasForSearch('Computer', $search_params);
9798
Search::constructSQL($data);
@@ -120,6 +121,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options
120121
foreach ($values as $v) {
121122
$value .= $v . $line_delimiter;
122123
}
124+
123125
$value = preg_replace('/' . Search::LBBR . '/', '<br>', $value);
124126
$value = preg_replace('/' . Search::LBHR . '/', '<hr>', $value);
125127
$value = '<div class="fup-popup">' . $value . '</div>';
@@ -147,12 +149,8 @@ public static function getSpecificValueToDisplay($field, $values, array $options
147149

148150
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
149151
{
150-
if ($item instanceof PluginDatabaseinventoryComputerGroup) {
151-
switch ($tabnum) {
152-
case 1:
153-
self::showForItem($item);
154-
break;
155-
}
152+
if ($item instanceof PluginDatabaseinventoryComputerGroup && $tabnum === 1) {
153+
self::showForItem($item);
156154
}
157155

158156
return true;
@@ -164,9 +162,8 @@ private function countDynamicItems()
164162
$data = Search::prepareDatasForSearch('Computer', $search_params);
165163
Search::constructSQL($data);
166164
Search::constructData($data);
167-
$count = $data['data']['totalcount'];
168165

169-
return $count;
166+
return $data['data']['totalcount'];
170167
}
171168

172169
public function isDynamicSearchMatchComputer(Computer $computer)
@@ -183,13 +180,13 @@ public function isDynamicSearchMatchComputer(Computer $computer)
183180
if (!isset($_SESSION['glpiname'])) {
184181
$_SESSION['glpiname'] = 'databaseinventory_plugin';
185182
}
183+
186184
$search_params = Search::manageParams('Computer', $search);
187185
$data = Search::prepareDatasForSearch('Computer', $search_params);
188186
Search::constructSQL($data);
189187
Search::constructData($data);
190-
$count = $data['data']['totalcount'];
191188

192-
return $count;
189+
return $data['data']['totalcount'];
193190
}
194191

195192
private static function showForItem(PluginDatabaseinventoryComputerGroup $computergroup)
@@ -204,16 +201,16 @@ private static function showForItem(PluginDatabaseinventoryComputerGroup $comput
204201
$firsttime = true;
205202
// load dynamic search criteria from DB if exist
206203
$computergroup_dynamic = new self();
207-
if (
208-
$computergroup_dynamic->getFromDBByCrit([
209-
'plugin_databaseinventory_computergroups_id' => $ID,
210-
])
211-
) {
212-
$p = $search_params = Search::manageParams('Computer', unserialize($computergroup_dynamic->fields['search']));
204+
if ($computergroup_dynamic->getFromDBByCrit([
205+
'plugin_databaseinventory_computergroups_id' => $ID,
206+
])) {
207+
$p = Search::manageParams('Computer', unserialize($computergroup_dynamic->fields['search']));
208+
$search_params = $p;
213209
$firsttime = false;
214210
} else {
215211
// retrieve filter value from search if exist and reset it
216-
$p = $search_params = Search::manageParams('Computer', $_GET);
212+
$p = Search::manageParams('Computer', $_GET);
213+
$search_params = $p;
217214
if (isset($_SESSION['glpisearch']['Computer'])) {
218215
unset($_SESSION['glpisearch']['Computer']);
219216
}
@@ -268,9 +265,9 @@ public static function install(Migration $migration)
268265

269266
$table = self::getTable();
270267
if (!$DB->tableExists($table)) {
271-
$migration->displayMessage("Installing $table");
268+
$migration->displayMessage('Installing ' . $table);
272269
$query = <<<SQL
273-
CREATE TABLE IF NOT EXISTS `$table` (
270+
CREATE TABLE IF NOT EXISTS `{$table}` (
274271
`id` int {$default_key_sign} NOT NULL AUTO_INCREMENT,
275272
`plugin_databaseinventory_computergroups_id` int {$default_key_sign} NOT NULL DEFAULT '0',
276273
`search` text,

0 commit comments

Comments
 (0)