Skip to content

Commit 0263903

Browse files
authored
Add php-cs-fixer (#5)
1 parent f620057 commit 0263903

File tree

73 files changed

+13901
-11374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+13901
-11374
lines changed

.php-cs-fixer.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$finder = Finder::create()
7+
->in(__DIR__)
8+
->name('*.php');
9+
10+
$config = new Config();
11+
12+
$rules = [
13+
'@PER-CS2.0' => true,
14+
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
15+
];
16+
17+
return $config
18+
->setRules($rules)
19+
->setFinder($finder)
20+
->setUsingCache(false);

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"tecnickcom/tcpdf": "^6.4"
66
},
77
"require-dev": {
8-
"friendsofphp/php-cs-fixer": "^3.64",
8+
"friendsofphp/php-cs-fixer": "^3.66",
99
"glpi-project/tools": "^0.7.4",
1010
"php-parallel-lint/php-parallel-lint": "^1.4",
1111
"phpstan/phpstan": "^1.12"

composer.lock

+21-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front/config.form.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@
3030
* --------------------------------------------------------------------------
3131
*/
3232

33-
include ("../../../inc/includes.php");
33+
include('../../../inc/includes.php');
3434

3535
// No autoload when plugin is not activated
3636
require_once('../inc/config.class.php');
3737

3838
$config = new PluginPdfConfig();
39-
if (isset($_POST["update"])) {
40-
$config->check($_POST['id'], UPDATE);
39+
if (isset($_POST['update'])) {
40+
$config->check($_POST['id'], UPDATE);
4141

42-
$config->update($_POST);
42+
$config->update($_POST);
4343

44-
Html::back();
44+
Html::back();
4545
}
46-
Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".
46+
Html::redirect($CFG_GLPI['root_doc'] . '/front/config.form.php?forcetab=' .
4747
urlencode('PluginPdfConfig$1'));

front/export.massive.php

+22-21
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,39 @@
3030
* --------------------------------------------------------------------------
3131
*/
3232

33-
include ("../../../inc/includes.php");
33+
include('../../../inc/includes.php');
3434

3535
Plugin::load('pdf', true);
3636

37-
$type = $_SESSION["plugin_pdf"]["type"];
37+
$type = $_SESSION['plugin_pdf']['type'];
3838
$item = new $type();
3939

40-
$tab_id = unserialize($_SESSION["plugin_pdf"]["tab_id"]);
41-
unset($_SESSION["plugin_pdf"]["tab_id"]);
40+
$tab_id = unserialize($_SESSION['plugin_pdf']['tab_id']);
41+
unset($_SESSION['plugin_pdf']['tab_id']);
4242

43-
$result = $DB->request('glpi_plugin_pdf_preferences',
44-
['SELECT' => 'tabref',
45-
'WHERE' => ['users_ID' => $_SESSION['glpiID'],
46-
'itemtype' => $type]]);
43+
$result = $DB->request(
44+
'glpi_plugin_pdf_preferences',
45+
['SELECT' => 'tabref',
46+
'WHERE' => ['users_ID' => $_SESSION['glpiID'],
47+
'itemtype' => $type]],
48+
);
4749

4850
$tab = [];
4951

5052
foreach ($result as $data) {
51-
if ($data["tabref"] == 'landscape') {
52-
$pag = 1;
53-
} else {
54-
$tab[]= $data["tabref"];
55-
}
53+
if ($data['tabref'] == 'landscape') {
54+
$pag = 1;
55+
} else {
56+
$tab[] = $data['tabref'];
57+
}
58+
}
59+
if (empty($tab)) {
60+
$tab[] = $type . '$main';
5661
}
57-
if (empty($tab)) {
58-
$tab[] = $type.'$main';
59-
}
6062

6163
if (isset($PLUGIN_HOOKS['plugin_pdf'][$type])) {
62-
63-
$itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item);
64-
$itempdf->generatePDF($tab_id, $tab, (isset($pag) ? $pag : 0));
64+
$itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item);
65+
$itempdf->generatePDF($tab_id, $tab, (isset($pag) ? $pag : 0));
6566
} else {
66-
die("Missing hook");
67-
}
67+
die('Missing hook');
68+
}

front/export.php

+30-32
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,47 @@
3333
define('GLPI_KEEP_CSRF_TOKEN', true); // 0.90
3434
$token = (isset($_POST['_glpi_csrf_token']) ? $_POST['_glpi_csrf_token'] : false);
3535

36-
include ("../../../inc/includes.php");
36+
include('../../../inc/includes.php');
3737

3838
/* 0.85 Hack to allow multiple exports, yes this is an hack, yes an awful one */
3939
if (!isset($_SESSION['glpicsrftokens'][$token])) {
40-
$_SESSION['glpicsrftokens'][$token] = time() + GLPI_CSRF_EXPIRES;
40+
$_SESSION['glpicsrftokens'][$token] = time() + GLPI_CSRF_EXPIRES;
4141
}
4242

4343
Plugin::load('pdf', true);
4444

4545
$dbu = new DbUtils();
4646

47-
if (isset($_POST["plugin_pdf_inventory_type"])
48-
&& ($item = $dbu->getItemForItemtype($_POST["plugin_pdf_inventory_type"]))
49-
&& isset($_POST["itemID"])) {
47+
if (isset($_POST['plugin_pdf_inventory_type'])
48+
&& ($item = $dbu->getItemForItemtype($_POST['plugin_pdf_inventory_type']))
49+
&& isset($_POST['itemID'])) {
50+
$type = $_POST['plugin_pdf_inventory_type'];
51+
$item->check($_POST['itemID'], READ);
5052

51-
$type = $_POST["plugin_pdf_inventory_type"];
52-
$item->check($_POST["itemID"], READ);
53+
if (isset($_SESSION['plugin_pdf'][$type])) {
54+
unset($_SESSION['plugin_pdf'][$type]);
55+
}
5356

54-
if (isset($_SESSION["plugin_pdf"][$type])) {
55-
unset($_SESSION["plugin_pdf"][$type]);
56-
}
57+
$tab = [];
5758

58-
$tab = [];
59+
if (isset($_POST['item'])) {
60+
foreach ($_POST['item'] as $key => $val) {
61+
if (!in_array($key, $tab)) {
62+
$tab[] = $_SESSION['plugin_pdf'][$type][] = $key;
63+
}
64+
}
65+
}
66+
if (empty($tab)) {
67+
$tab[] = $type . '$main';
68+
}
5969

60-
if (isset($_POST['item'])) {
61-
foreach ($_POST['item'] as $key => $val) {
62-
if (!in_array($key, $tab)) {
63-
$tab[] = $_SESSION["plugin_pdf"][$type][] = $key;
64-
}
65-
}
66-
}
67-
if (empty($tab)) {
68-
$tab[] = $type.'$main';
69-
}
70-
71-
if (isset($PLUGIN_HOOKS['plugin_pdf'][$type])
72-
&& class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) {
73-
74-
$itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item);
75-
$itempdf->generatePDF([$_POST["itemID"]], $tab, (isset($_POST["page"]) ? $_POST["page"] : 0));
76-
} else {
77-
die("Missing hook");
78-
}
70+
if (isset($PLUGIN_HOOKS['plugin_pdf'][$type])
71+
&& class_exists($PLUGIN_HOOKS['plugin_pdf'][$type])) {
72+
$itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($item);
73+
$itempdf->generatePDF([$_POST['itemID']], $tab, (isset($_POST['page']) ? $_POST['page'] : 0));
74+
} else {
75+
die('Missing hook');
76+
}
7977
} else {
80-
die("Missing context");
81-
}
78+
die('Missing context');
79+
}

front/preference.form.php

+20-21
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,31 @@
3030
* --------------------------------------------------------------------------
3131
*/
3232

33-
include_once ("../../../inc/includes.php");
33+
include_once('../../../inc/includes.php');
3434

3535
//Save user preferences
3636
if (isset($_POST['plugin_pdf_user_preferences_save'])
37-
&& isset($_POST["plugin_pdf_inventory_type"])) {
38-
39-
$DB->query("DELETE
37+
&& isset($_POST['plugin_pdf_inventory_type'])) {
38+
$DB->query("DELETE
4039
FROM `glpi_plugin_pdf_preferences`
41-
WHERE `users_id` ='" . $_SESSION["glpiID"] . "'
42-
AND `itemtype`='" . $_POST["plugin_pdf_inventory_type"]."'");
40+
WHERE `users_id` ='" . $_SESSION['glpiID'] . "'
41+
AND `itemtype`='" . $_POST['plugin_pdf_inventory_type'] . "'");
4342

44-
if (isset($_POST['item'])) {
45-
foreach ($_POST['item'] as $key => $val) {
46-
$DB->query("INSERT INTO `glpi_plugin_pdf_preferences`
43+
if (isset($_POST['item'])) {
44+
foreach ($_POST['item'] as $key => $val) {
45+
$DB->query("INSERT INTO `glpi_plugin_pdf_preferences`
4746
(`id` ,`users_id` ,`itemtype` ,`tabref`)
48-
VALUES (NULL , '".$_SESSION["glpiID"]."',
49-
'".$_POST["plugin_pdf_inventory_type"]."', '$key')");
50-
}
51-
}
52-
if (isset($_POST["page"]) && $_POST["page"]) {
53-
$DB->query("INSERT INTO `glpi_plugin_pdf_preferences`
47+
VALUES (NULL , '" . $_SESSION['glpiID'] . "',
48+
'" . $_POST['plugin_pdf_inventory_type'] . "', '$key')");
49+
}
50+
}
51+
if (isset($_POST['page']) && $_POST['page']) {
52+
$DB->query("INSERT INTO `glpi_plugin_pdf_preferences`
5453
(`id` ,`users_id` ,`itemtype` ,`tabref`)
55-
VALUES (NULL , '".$_SESSION["glpiID"]."',
56-
'".$_POST["plugin_pdf_inventory_type"]."', 'landscape')");
57-
}
58-
Html::back();
54+
VALUES (NULL , '" . $_SESSION['glpiID'] . "',
55+
'" . $_POST['plugin_pdf_inventory_type'] . "', 'landscape')");
56+
}
57+
Html::back();
5958
} else {
60-
Html::redirect("../../../front/preference.php");
61-
}
59+
Html::redirect('../../../front/preference.php');
60+
}

0 commit comments

Comments
 (0)