Skip to content

Commit 13374f9

Browse files
committed
Switch to PSR-12
1 parent b661fde commit 13374f9

35 files changed

+4763
-4321
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Continuous integration"
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
- "develop"
8+
tags:
9+
- "*"
10+
pull_request:
11+
workflow_dispatch:
12+
13+
jobs:
14+
lint:
15+
name: "Lint"
16+
runs-on: "ubuntu-latest"
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- {php-version: "7.4"}
22+
steps:
23+
- name: "Checkout"
24+
uses: "actions/checkout@v3"
25+
- name: "Setup PHP"
26+
uses: "shivammathur/setup-php@v2"
27+
with:
28+
php-version: "${{ matrix.php-version }}"
29+
coverage: "none"
30+
tools: "composer, cs2pr"
31+
- name: "Get Composer cache directory"
32+
id: "composer-cache"
33+
run: |
34+
echo "::set-output name=dir::$(composer config cache-files-dir)"
35+
- name: "Restore dependencies cache"
36+
uses: "actions/cache@v3"
37+
with:
38+
path: "${{ steps.composer-cache.outputs.dir }}"
39+
key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}"
40+
- name: "Install Composer dependencies"
41+
run: |
42+
composer install --ansi --no-interaction --no-progress --prefer-dist
43+
- name: "PHP Parallel Lint"
44+
run: |
45+
vendor/bin/parallel-lint --colors --checkstyle --exclude ./vendor/ . | cs2pr
46+
- name: "PHP_CodeSniffer"
47+
run: |
48+
vendor/bin/phpcs -q --report=checkstyle | cs2pr
49+
- name: "Check for missing/outdated headers"
50+
run: |
51+
vendor/bin/licence-headers-check --ansi --no-interaction

.phpcs.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<file>.</file>
4+
<exclude-pattern>/.git/</exclude-pattern>
5+
<exclude-pattern type="relative">^vendor/</exclude-pattern>
6+
7+
<arg name="colors" />
8+
<arg name="extensions" value="php" />
9+
<arg value="p" />
10+
<arg name="warning-severity" value="0" />
11+
12+
<rule ref="PSR12">
13+
<exclude name="Generic.Files.LineLength" />
14+
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
15+
</rule>
16+
<rule ref="Generic.Arrays.ArrayIndent"></rule>
17+
</ruleset>

ajax/container_display_condition.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31-
include ("../../../inc/includes.php");
31+
include("../../../inc/includes.php");
3232

3333
if (isset($_GET['action'])) {
3434
if ($_GET['action'] === 'get_add_form') {
@@ -39,21 +39,19 @@
3939
$status_override->getFromDB($_GET['id']);
4040
$status_override->showForm($_GET['id'], $_GET);
4141
}
42-
4342
} else if (isset($_POST['action'])) {
44-
if($_POST['action'] === 'get_itemtype_so') {
45-
if(isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
43+
if ($_POST['action'] === 'get_itemtype_so') {
44+
if (isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
4645
echo PluginFieldsContainerDisplayCondition::showItemtypeFieldForm($_POST['itemtype']) ;
4746
} else {
4847
echo "";
4948
}
50-
} else if($_POST['action'] === 'get_condition_switch_so') {
51-
if(isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) {
49+
} else if ($_POST['action'] === 'get_condition_switch_so') {
50+
if (isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) {
5251
echo PluginFieldsContainerDisplayCondition::showSearchOptionCondition($_POST['search_option_id'], $_POST['itemtype']);
5352
} else {
5453
echo "";
5554
}
56-
5755
}
5856
} else {
5957
http_response_code(400);

ajax/container_itemtypes_dropdown.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31-
include ("../../../inc/includes.php");
31+
include("../../../inc/includes.php");
3232

3333
PluginFieldsContainer::showFormItemtype($_REQUEST);

ajax/container_subtype_dropdown.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31-
include ("../../../inc/includes.php");
31+
include("../../../inc/includes.php");
3232

3333
PluginFieldsContainer::showFormSubtype($_REQUEST, true);

ajax/reorder.php

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31-
include ("../../../inc/includes.php");
31+
include("../../../inc/includes.php");
3232

33-
if (!array_key_exists('container_id', $_POST)
33+
if (
34+
!array_key_exists('container_id', $_POST)
3435
|| !array_key_exists('old_order', $_POST)
35-
|| !array_key_exists('new_order', $_POST)) {
36-
// Missing input
37-
exit();
36+
|| !array_key_exists('new_order', $_POST)
37+
) {
38+
// Missing input
39+
exit();
3840
}
3941

4042
$table = PluginFieldsField::getTable();
@@ -44,57 +46,57 @@
4446

4547
// Retrieve id of field to update
4648
$field_iterator = $DB->request(
47-
[
48-
'SELECT' => 'id',
49-
'FROM' => $table,
50-
'WHERE' => [
51-
'plugin_fields_containers_id' => $container_id,
52-
'ranking' => $old_order,
53-
],
54-
]
49+
[
50+
'SELECT' => 'id',
51+
'FROM' => $table,
52+
'WHERE' => [
53+
'plugin_fields_containers_id' => $container_id,
54+
'ranking' => $old_order,
55+
],
56+
]
5557
);
5658

5759
if (0 === $field_iterator->count()) {
58-
// Unknown field
59-
exit();
60+
// Unknown field
61+
exit();
6062
}
6163

6264
$field_id = $field_iterator->current()['id'];
6365

6466
// Move all elements to their new ranking
6567
if ($old_order < $new_order) {
66-
$DB->update(
67-
$table,
68-
[
69-
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' - 1'),
70-
],
71-
[
72-
'plugin_fields_containers_id' => $container_id,
73-
['ranking' => ['>', $old_order]],
74-
['ranking' => ['<=', $new_order]],
75-
]
76-
);
68+
$DB->update(
69+
$table,
70+
[
71+
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' - 1'),
72+
],
73+
[
74+
'plugin_fields_containers_id' => $container_id,
75+
['ranking' => ['>', $old_order]],
76+
['ranking' => ['<=', $new_order]],
77+
]
78+
);
7779
} else {
78-
$DB->update(
79-
$table,
80-
[
81-
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' + 1'),
82-
],
83-
[
84-
'plugin_fields_containers_id' => $container_id,
85-
['ranking' => ['<', $old_order]],
86-
['ranking' => ['>=', $new_order]],
87-
]
88-
);
80+
$DB->update(
81+
$table,
82+
[
83+
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' + 1'),
84+
],
85+
[
86+
'plugin_fields_containers_id' => $container_id,
87+
['ranking' => ['<', $old_order]],
88+
['ranking' => ['>=', $new_order]],
89+
]
90+
);
8991
}
9092

9193
// Update current element
9294
$DB->update(
93-
$table,
94-
[
95-
'ranking' => $new_order,
96-
],
97-
[
98-
'id' => $field_id,
99-
]
95+
$table,
96+
[
97+
'ranking' => $new_order,
98+
],
99+
[
100+
'id' => $field_id,
101+
]
100102
);

ajax/status_override.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31-
include ("../../../inc/includes.php");
31+
include("../../../inc/includes.php");
3232

3333
if (isset($_GET['action'])) {
3434
if ($_GET['action'] === 'get_status_dropdown') {

ajax/viewtranslations.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,26 @@
3232
* @brief
3333
*/
3434

35-
include ('../../../inc/includes.php');
35+
include('../../../inc/includes.php');
3636
header("Content-Type: text/html; charset=UTF-8");
3737
Html::header_nocache();
3838

3939
Session::checkLoginUser();
4040

4141
if (!isset($_POST['itemtype']) || !isset($_POST['items_id']) || !isset($_POST['id'])) {
42-
exit();
42+
exit();
4343
}
4444

4545
$translation = new PluginFieldsLabelTranslation();
4646
if ($_POST['id'] == -1) {
47-
$canedit = $translation->can(-1, CREATE, $_POST);
47+
$canedit = $translation->can(-1, CREATE, $_POST);
4848
} else {
49-
$canedit = $translation->can($_POST['id'], UPDATE);
49+
$canedit = $translation->can($_POST['id'], UPDATE);
5050
}
5151
if ($canedit) {
5252
$translation->showFormForItem($_POST['itemtype'], $_POST['items_id'], $_POST['id']);
5353
} else {
54-
echo __('Access denied');
54+
echo __('Access denied');
5555
}
5656

5757
Html::ajaxFooter();

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"symfony/yaml": "^5.4"
55
},
66
"require-dev": {
7-
"glpi-project/tools": "^0.5"
7+
"glpi-project/tools": "^0.5",
8+
"php-parallel-lint/php-parallel-lint": "^1.3",
9+
"squizlabs/php_codesniffer": "^3.6"
810
},
911
"config": {
1012
"optimize-autoloader": true,

0 commit comments

Comments
 (0)