Skip to content

Commit

Permalink
Switch to PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Jun 3, 2022
1 parent b661fde commit 13374f9
Show file tree
Hide file tree
Showing 35 changed files with 4,763 additions and 4,321 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Continuous integration"

on:
push:
branches:
- "master"
- "develop"
tags:
- "*"
pull_request:
workflow_dispatch:

jobs:
lint:
name: "Lint"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
include:
- {php-version: "7.4"}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
tools: "composer, cs2pr"
- name: "Get Composer cache directory"
id: "composer-cache"
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: "Restore dependencies cache"
uses: "actions/cache@v3"
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}"
- name: "Install Composer dependencies"
run: |
composer install --ansi --no-interaction --no-progress --prefer-dist
- name: "PHP Parallel Lint"
run: |
vendor/bin/parallel-lint --colors --checkstyle --exclude ./vendor/ . | cs2pr
- name: "PHP_CodeSniffer"
run: |
vendor/bin/phpcs -q --report=checkstyle | cs2pr
- name: "Check for missing/outdated headers"
run: |
vendor/bin/licence-headers-check --ansi --no-interaction
17 changes: 17 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>/.git/</exclude-pattern>
<exclude-pattern type="relative">^vendor/</exclude-pattern>

<arg name="colors" />
<arg name="extensions" value="php" />
<arg value="p" />
<arg name="warning-severity" value="0" />

<rule ref="PSR12">
<exclude name="Generic.Files.LineLength" />
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
</rule>
<rule ref="Generic.Arrays.ArrayIndent"></rule>
</ruleset>
12 changes: 5 additions & 7 deletions ajax/container_display_condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/

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

if (isset($_GET['action'])) {
if ($_GET['action'] === 'get_add_form') {
Expand All @@ -39,21 +39,19 @@
$status_override->getFromDB($_GET['id']);
$status_override->showForm($_GET['id'], $_GET);
}

} else if (isset($_POST['action'])) {
if($_POST['action'] === 'get_itemtype_so') {
if(isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
if ($_POST['action'] === 'get_itemtype_so') {
if (isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
echo PluginFieldsContainerDisplayCondition::showItemtypeFieldForm($_POST['itemtype']) ;
} else {
echo "";
}
} else if($_POST['action'] === 'get_condition_switch_so') {
if(isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) {
} else if ($_POST['action'] === 'get_condition_switch_so') {
if (isset($_POST['search_option_id']) && (isset($_POST['itemtype']) && class_exists($_POST['itemtype']))) {
echo PluginFieldsContainerDisplayCondition::showSearchOptionCondition($_POST['search_option_id'], $_POST['itemtype']);
} else {
echo "";
}

}
} else {
http_response_code(400);
Expand Down
2 changes: 1 addition & 1 deletion ajax/container_itemtypes_dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
* -------------------------------------------------------------------------
*/

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

PluginFieldsContainer::showFormItemtype($_REQUEST);
2 changes: 1 addition & 1 deletion ajax/container_subtype_dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
* -------------------------------------------------------------------------
*/

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

PluginFieldsContainer::showFormSubtype($_REQUEST, true);
90 changes: 46 additions & 44 deletions ajax/reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
* -------------------------------------------------------------------------
*/

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

if (!array_key_exists('container_id', $_POST)
if (
!array_key_exists('container_id', $_POST)
|| !array_key_exists('old_order', $_POST)
|| !array_key_exists('new_order', $_POST)) {
// Missing input
exit();
|| !array_key_exists('new_order', $_POST)
) {
// Missing input
exit();
}

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

// Retrieve id of field to update
$field_iterator = $DB->request(
[
'SELECT' => 'id',
'FROM' => $table,
'WHERE' => [
'plugin_fields_containers_id' => $container_id,
'ranking' => $old_order,
],
]
[
'SELECT' => 'id',
'FROM' => $table,
'WHERE' => [
'plugin_fields_containers_id' => $container_id,
'ranking' => $old_order,
],
]
);

if (0 === $field_iterator->count()) {
// Unknown field
exit();
// Unknown field
exit();
}

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

// Move all elements to their new ranking
if ($old_order < $new_order) {
$DB->update(
$table,
[
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' - 1'),
],
[
'plugin_fields_containers_id' => $container_id,
['ranking' => ['>', $old_order]],
['ranking' => ['<=', $new_order]],
]
);
$DB->update(
$table,
[
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' - 1'),
],
[
'plugin_fields_containers_id' => $container_id,
['ranking' => ['>', $old_order]],
['ranking' => ['<=', $new_order]],
]
);
} else {
$DB->update(
$table,
[
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' + 1'),
],
[
'plugin_fields_containers_id' => $container_id,
['ranking' => ['<', $old_order]],
['ranking' => ['>=', $new_order]],
]
);
$DB->update(
$table,
[
'ranking' => new \QueryExpression($DB->quoteName('ranking') . ' + 1'),
],
[
'plugin_fields_containers_id' => $container_id,
['ranking' => ['<', $old_order]],
['ranking' => ['>=', $new_order]],
]
);
}

// Update current element
$DB->update(
$table,
[
'ranking' => $new_order,
],
[
'id' => $field_id,
]
$table,
[
'ranking' => $new_order,
],
[
'id' => $field_id,
]
);
2 changes: 1 addition & 1 deletion ajax/status_override.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/

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

if (isset($_GET['action'])) {
if ($_GET['action'] === 'get_status_dropdown') {
Expand Down
10 changes: 5 additions & 5 deletions ajax/viewtranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
* @brief
*/

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

Session::checkLoginUser();

if (!isset($_POST['itemtype']) || !isset($_POST['items_id']) || !isset($_POST['id'])) {
exit();
exit();
}

$translation = new PluginFieldsLabelTranslation();
if ($_POST['id'] == -1) {
$canedit = $translation->can(-1, CREATE, $_POST);
$canedit = $translation->can(-1, CREATE, $_POST);
} else {
$canedit = $translation->can($_POST['id'], UPDATE);
$canedit = $translation->can($_POST['id'], UPDATE);
}
if ($canedit) {
$translation->showFormForItem($_POST['itemtype'], $_POST['items_id'], $_POST['id']);
} else {
echo __('Access denied');
echo __('Access denied');
}

Html::ajaxFooter();
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"symfony/yaml": "^5.4"
},
"require-dev": {
"glpi-project/tools": "^0.5"
"glpi-project/tools": "^0.5",
"php-parallel-lint/php-parallel-lint": "^1.3",
"squizlabs/php_codesniffer": "^3.6"
},
"config": {
"optimize-autoloader": true,
Expand Down
Loading

0 comments on commit 13374f9

Please sign in to comment.