Skip to content

Commit 974c23b

Browse files
committed
phpcs et fix
1 parent 54c6ecb commit 974c23b

17 files changed

+123
-115
lines changed

.php-cs-fixer.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
<?php
22

3-
use PhpCsFixer\Config;
4-
use PhpCsFixer\Finder;
5-
6-
$finder = Finder::create()
3+
$finder = (new PhpCsFixer\Finder())
74
->in(__DIR__)
8-
->ignoreVCSIgnored(true)
9-
->name('*.php');
10-
11-
$config = new Config();
12-
13-
$rules = [
14-
'@PER-CS' => true, // Latest PER rules.
15-
];
5+
->exclude([
6+
'.git/',
7+
'node_modules/',
8+
'tools/',
9+
'vendor/',
10+
])
11+
;
1612

17-
return $config
18-
->setRules($rules)
13+
return (new PhpCsFixer\Config())
14+
->setUnsupportedPhpVersionAllowed(true) // allow upcoming PHP versions
15+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
16+
->setRules([
17+
'@PER-CS3x0' => true,
18+
'@PHP8x4Migration' => true,
19+
'fully_qualified_strict_types' => ['import_symbols' => true],
20+
'ordered_imports' => ['imports_order' => ['class', 'const', 'function']],
21+
'no_unused_imports' => true,
22+
'heredoc_indentation' => false, // This rule is mandatory due to a bug in `xgettext`, see https://savannah.gnu.org/bugs/?func=detailitem&item_id=62158
23+
'new_expression_parentheses' => false, // breaks compatibility with PHP < 8.4
24+
'phpdoc_scalar' => true, // Normalize scalar types identifiers in PHPDoc
25+
'phpdoc_types' => true, // Fixes types case in PHPDoc
26+
])
1927
->setFinder($finder)
20-
->setUsingCache(false);
21-
;
28+
;

.phpcs.xml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?xml version="1.0"?>
22
<ruleset>
3-
<file>.</file>
3+
<file>setup.php</file>
4+
<file>hook.php</file>
5+
<file>inc</file>
6+
<file>front</file>
47
<exclude-pattern>/.git/</exclude-pattern>
5-
<exclude-pattern type="relative">^config/</exclude-pattern>
6-
<exclude-pattern type="relative">^files/</exclude-pattern>
7-
<exclude-pattern type="relative">^lib/</exclude-pattern>
8-
<exclude-pattern type="relative">^marketplace/</exclude-pattern>
9-
<exclude-pattern type="relative">^node_modules/</exclude-pattern>
10-
<exclude-pattern type="relative">^plugins/</exclude-pattern>
11-
<exclude-pattern type="relative">^tests/config/</exclude-pattern>
12-
<exclude-pattern type="relative">^tests/files/</exclude-pattern>
8+
<exclude-pattern type="relative">^tools/</exclude-pattern>
139
<exclude-pattern type="relative">^vendor/</exclude-pattern>
1410

1511
<arg name="warning-severity" value="0" />
@@ -19,9 +15,6 @@
1915
<arg name="extensions" value="php" />
2016

2117
<rule ref="PSR12">
22-
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
23-
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
24-
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
2518
</rule>
2619

2720
<rule ref="Generic.Arrays.ArrayIndent"></rule>

composer.json

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
{
2-
"require": {
3-
"php": ">=8.2"
4-
},
2+
"name": "salleman/reservation",
3+
"description": "Plugin Reservation pour GLPI",
54
"require-dev": {
6-
"glpi-project/tools": "^0.8",
5+
"squizlabs/php_codesniffer": "^4.0",
6+
"friendsoftwig/twigcs": "^6.0",
7+
"friendsofphp/php-cs-fixer": "^3.92",
8+
"glpi-project/phpstan-glpi": "^1.1",
9+
"glpi-project/tools": "^0.8.3",
10+
"php-parallel-lint/php-parallel-lint": "^1.4",
711
"phpstan/phpstan": "^2.1",
8-
"squizlabs/php_codesniffer": "^4.0"
12+
"phpstan/phpstan-deprecation-rules": "^2.0",
13+
"phpunit/phpunit": "^11.5"
14+
},
15+
"require": {
16+
"php": "^8.3"
17+
},
18+
"scripts": {
19+
"lint": "parallel-lint --show-deprecated --colors --exclude ./vendor/ .",
20+
"php-cs-fixer" : "php-cs-fixer check --show-progress=dots --verbose --diff"
921
},
10-
"config": {
11-
"optimize-autoloader": true,
12-
"platform": {
13-
"php": "8.2.99"
14-
},
15-
"sort-packages": true
16-
}
17-
}
22+
"authors": [
23+
{
24+
"name": "Sylvain Allemand",
25+
"email": "salleman@math.u-bordeaux.fr"
26+
}
27+
]
28+
}

front/config.form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
Html::footer();
7171
} else {
7272
Html::header(__('Setup'), '', "config", "plugins");
73-
echo "<div class='center'><br><br>" .
74-
"<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br>";
73+
echo "<div class='center'><br><br>"
74+
. "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br>";
7575
echo "<b>" . __('Please activate the plugin', 'reservation') . "</b></div>";
7676
Html::footer();
7777
}

front/menu.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
$planning_end = $CFG_GLPI['planning_end'];
4040
$planning_begin_time = explode(":", $planning_begin);
4141
$planning_end_time = explode(":", $planning_end);
42-
$planning_begin_date = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
43-
$planning_end_date = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
42+
$planning_begin_date = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 0o0, $month, $day, $year));
43+
$planning_end_date = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 0o0, $month, $day, $year));
4444

4545
$form_dates["begin"] = date("Y-m-d H:i:s", $begin_time);
4646
if ($planning_end_date > date("Y-m-d H:i:s", time())) {
4747
$form_dates['end'] = $planning_end_date;
4848
} else {
49-
$form_dates['end'] = date("Y-m-d H:i:s", mktime(23, 59, 00, $month, $day, $year));
49+
$form_dates['end'] = date("Y-m-d H:i:s", mktime(23, 59, 0o0, $month, $day, $year));
5050
}
5151

5252
if (isset($_POST['date_begin'])) {
@@ -70,8 +70,8 @@
7070
$month = date("m", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
7171
$year = date("Y", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
7272

73-
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
74-
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
73+
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 0o0, $month, $day, $year));
74+
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 0o0, $month, $day, $year));
7575
}
7676
if (isset($_POST['previousday']) || isset($_GET['previousday'])) {
7777
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
@@ -80,8 +80,8 @@
8080
$month = date("m", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
8181
$year = date("Y", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
8282

83-
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
84-
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
83+
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 0o0, $month, $day, $year));
84+
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 0o0, $month, $day, $year));
8585
}
8686
if (isset($_GET['reset'])) {
8787
unset($_SESSION['glpi_plugin_reservation_form_dates']);
@@ -116,10 +116,10 @@
116116

117117
$reservation_types = PluginReservationMenu::getReservationTypes();
118118

119-
TemplateRenderer::getInstance()->display('@reservation/dates_forms.html.twig', [
119+
TemplateRenderer::getInstance()->display('@reservation/dates_forms.html.twig', [
120120
'reservation_types' => $reservation_types,
121121
'default_location' => (int) ($_POST['locations_id'] ?? User::getById(Session::getLoginUserID())->fields['locations_id'] ?? 0),
122-
'form_dates' => $form_dates
122+
'form_dates' => $form_dates,
123123
]);
124124

125125
$menu = new PluginReservationMenu();

front/multiedit.form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
Html::footer();
5454
} else {
5555
Html::header(__('Setup'), '', "config", "plugins");
56-
echo "<div class='center'><br><br>" .
57-
"<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br>";
56+
echo "<div class='center'><br><br>"
57+
. "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br>";
5858
echo "<b>" . __('Please activate the plugin', 'reservation') . "</b></div>";
5959
Html::footer();
6060
}

front/query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$config = new PluginReservationConfig();
1212
$read_make_access = $config->getConfigurationValue("read_make_access");
1313
$access = [CREATE, UPDATE, DELETE];
14-
14+
1515
if ($read_make_access) {
1616
$access = [READ, ReservationItem::RESERVEANITEM, CREATE, UPDATE, DELETE, PURGE];
1717
}

hook.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Install hook
55
*
6-
* @return boolean
6+
* @return bool
77
*/
88
function plugin_reservation_install()
99
{
@@ -99,7 +99,6 @@ function plugin_reservation_install()
9999
UNIQUE (`name`)
100100
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation}";
101101
$DB->doQuery($query, $DB->error());
102-
103102

104103
$query = "INSERT INTO `glpi_plugin_reservation_configs` (`name` , `value`)
105104
VALUES (\"mode_auto\",0),
@@ -151,7 +150,7 @@ function plugin_reservation_install()
151150
/**
152151
* Uninstall hook
153152
*
154-
* @return boolean
153+
* @return bool
155154
*/
156155
function plugin_reservation_uninstall()
157156
{

inc/api.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
use Glpi\Api\API;
54

65
include_once(__DIR__ . 'includes.php');
@@ -74,8 +73,8 @@ public function call()
7473
return;
7574
case "reservationItem":
7675
return $this->reservationItemRoutes();
77-
// case "user":
78-
// return $this->userRoutes();
76+
// case "user":
77+
// return $this->userRoutes();
7978
default:
8079
return $this->returnError(
8180
__("resource not found"),
@@ -135,15 +134,15 @@ private function searchReservations()
135134
$response = "Use GET request !";
136135
break;
137136
case "GET":
138-
$response = array();
137+
$response = [];
139138
$begin = $this->parameters['begin'];
140139
$end = $this->parameters['end'];
141140
$user = $this->parameters['user'];
142141

143-
$filters = array(
142+
$filters = [
144143
"`begin` >= '" . $begin . "'",
145144
"`end` <= '" . $end . "'",
146-
);
145+
];
147146

148147
if (isset($user)) {
149148
array_push($filters, "`users_id` = '" . $user . "'");
@@ -205,7 +204,7 @@ private function searchReservationItems()
205204
$response = "Use GET request !";
206205
break;
207206
case "GET":
208-
$response = array();
207+
$response = [];
209208
$begin = $this->parameters['begin'];
210209
$end = $this->parameters['end'];
211210

@@ -443,7 +442,7 @@ private function todayReservationOfUserId()
443442
$month = date("m", time());
444443
$year = date("Y", time());
445444
$now = date("Y-m-d H:i:s", $time);
446-
$end_day = date("Y-m-d H:i:s", mktime(23, 59, 00, $month, $day, $year));
445+
$end_day = date("Y-m-d H:i:s", mktime(23, 59, 0o0, $month, $day, $year));
447446
$res = PluginReservationReservation::getAllReservations(
448447
[
449448
"`end` >= '" . $now . "'",
@@ -642,7 +641,7 @@ public function parseIncomingParams($is_inline_doc = false)
642641
$content_type = "";
643642
if (isset($_SERVER['CONTENT_TYPE'])) {
644643
$content_type = $_SERVER['CONTENT_TYPE'];
645-
} else if (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
644+
} elseif (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
646645
$content_type = $_SERVER['HTTP_CONTENT_TYPE'];
647646
} else {
648647
if (!$is_inline_doc) {
@@ -654,7 +653,7 @@ public function parseIncomingParams($is_inline_doc = false)
654653
foreach ($body_params as $param_name => $param_value) {
655654
$parameters[$param_name] = $param_value;
656655
}
657-
} else if (strlen($body) > 0) {
656+
} elseif (strlen($body) > 0) {
658657
$this->returnError(
659658
"JSON payload seems not valid",
660659
400,
@@ -663,7 +662,7 @@ public function parseIncomingParams($is_inline_doc = false)
663662
);
664663
}
665664
$this->format = "json";
666-
} else if (strpos($content_type, "multipart/form-data") !== false) {
665+
} elseif (strpos($content_type, "multipart/form-data") !== false) {
667666
if (count($_FILES) <= 0) {
668667
// likely uploaded files is too big so $_REQUEST will be empty also.
669668
// see http://us.php.net/manual/en/ini.core.php#ini.post-max-size
@@ -691,7 +690,7 @@ public function parseIncomingParams($is_inline_doc = false)
691690
$parameters['upload_result'] = [];
692691
$parameters['input']->_filename = [];
693692
$parameters['input']->_prefix_filename = [];
694-
} else if (strpos($content_type, "application/x-www-form-urlencoded") !== false) {
693+
} elseif (strpos($content_type, "application/x-www-form-urlencoded") !== false) {
695694
parse_str($body, $postvars);
696695
foreach ($postvars as $field => $value) {
697696
$parameters[$field] = $value;

inc/category.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function deleteCategory($name)
8181
$DB->deleteOrDie(
8282
$items_table,
8383
[
84-
'categories_id' => $this->getId()
84+
'categories_id' => $this->getId(),
8585
]
8686
);
8787

@@ -144,7 +144,7 @@ public static function getReservationItems($begin = '', $end = '', $available =
144144
$itemtable => [
145145
'ON' => [
146146
'glpi_reservationitems' => 'items_id',
147-
$itemtable => 'id',
147+
$itemtable => 'id',
148148
[
149149
'AND' => [
150150
'glpi_reservationitems.itemtype' => $itemtype,
@@ -170,8 +170,8 @@ public static function getReservationItems($begin = '', $end = '', $available =
170170
'ON' => [
171171
$category_items_table => 'categories_id',
172172
$categories_table => 'id',
173-
]
174-
]
173+
],
174+
],
175175
],
176176
'WHERE' => [
177177
"$itemtable.is_deleted" => 0,
@@ -195,7 +195,7 @@ public static function getReservationItems($begin = '', $end = '', $available =
195195
];
196196
}
197197
if ($filter_is_active) {
198-
$criteria['WHERE'][] = ['glpi_reservationitems.is_active' => '1'];
198+
$criteria['WHERE'][] = ['glpi_reservationitems.is_active' => '1'];
199199
}
200200
if ($available) {
201201
$criteria['WHERE'][] = ['glpi_reservations.id' => null];

0 commit comments

Comments
 (0)