Skip to content

Commit

Permalink
Add php-cs-fixer (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored Oct 2, 2024
1 parent 9f738c9 commit db7f484
Show file tree
Hide file tree
Showing 39 changed files with 2,966 additions and 1,300 deletions.
20 changes: 20 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->name('*.php');

$config = new Config();

$rules = [
'@PER-CS2.0' => true,
'trailing_comma_in_multiline' => ['elements' => ['arguments', 'array_destructuring', 'arrays']], // For PHP 7.4 compatibility
];

return $config
->setRules($rules)
->setFinder($finder)
->setUsingCache(false);
8 changes: 4 additions & 4 deletions ajax/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
* -------------------------------------------------------------------------
*/

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

use Glpi\Http\Response;

if (isset($_GET['action']) && $_GET['action'] === 'get_fields_html') {
$containers_id = $_GET['id'];
$itemtype = $_GET['itemtype'];
$items_id = (int)$_GET['items_id'];
$items_id = (int) $_GET['items_id'];
$type = $_GET['type'];
$subtype = $_GET['subtype'];
$input = $_GET['input'];
Expand All @@ -52,10 +52,10 @@
$containers_id,
$item,
$type,
$subtype
$subtype,
);
} else {
echo "";
echo '';
}
} else {
Response::sendError(404, 'Not Found');
Expand Down
12 changes: 6 additions & 6 deletions ajax/container_display_condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@
* -------------------------------------------------------------------------
*/

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

if (isset($_GET['action'])) {
if ($_GET['action'] === 'get_add_form') {
$status_override = new PluginFieldsContainerDisplayCondition();
$status_override->showForm(0, $_GET);
} else if ($_GET['action'] === 'get_edit_form') {
} elseif ($_GET['action'] === 'get_edit_form') {
$status_override = new PluginFieldsContainerDisplayCondition();
$status_override->getFromDB($_GET['id']);
$status_override->showForm($_GET['id'], $_GET);
}
} else if (isset($_POST['action'])) {
} elseif (isset($_POST['action'])) {
if ($_POST['action'] === 'get_itemtype_so') {
if (isset($_POST['itemtype']) && class_exists($_POST['itemtype'])) {
echo PluginFieldsContainerDisplayCondition::showItemtypeFieldForm($_POST['itemtype']) ;
} else {
echo "";
echo '';
}
} else if ($_POST['action'] === 'get_condition_switch_so') {
} elseif ($_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 "";
echo '';
}
}
} else {
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);
22 changes: 11 additions & 11 deletions ajax/field_specific_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

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

Expand All @@ -57,7 +57,7 @@
if ($field->isNewItem()) {
Dropdown::showFromArray('allowed_values', PluginFieldsToolbox::getGlpiItemtypes(), [
'display_emptychoice' => true,
'multiple' => true
'multiple' => true,
]);
} else {
$allowed_itemtypes = !empty($field->fields['allowed_values'])
Expand All @@ -71,14 +71,14 @@ function ($itemtype) {
? $itemtype::getTypeName(Session::getPluralNumber())
: $itemtype;
},
$allowed_itemtypes
)
$allowed_itemtypes,
),
);
}
echo '</td>';
} else {
$dropdown_matches = [];
$is_dropdown = $type == 'dropdown' || preg_match('/^dropdown-(?<class>.+)$/', $type, $dropdown_matches) === 1;
$is_dropdown = $type == 'dropdown' || preg_match('/^dropdown-(?<class>.+)$/', $type, $dropdown_matches) === 1;

// Display "default value(s)" field
echo '<td>';
Expand All @@ -94,7 +94,7 @@ function ($itemtype) {

echo '<td>';
if ($is_dropdown) {
$multiple = (bool)($_POST['multiple'] ?? $field->fields['multiple']);
$multiple = (bool) ($_POST['multiple'] ?? $field->fields['multiple']);

if ($field->isNewItem()) {
Dropdown::showYesNo(
Expand All @@ -103,7 +103,7 @@ function ($itemtype) {
-1,
[
'rand' => $rand,
]
],
);
} else {
echo Dropdown::getYesNo($multiple);
Expand All @@ -128,27 +128,27 @@ function ($itemtype) {
'entity_restrict' => -1,
'multiple' => $multiple,
'rand' => $rand,
]
],
);
}
echo '</div>';
Ajax::updateItemOnSelectEvent(
"dropdown_multiple$rand",
"plugin_fields_specific_fields_$rand",
"../ajax/field_specific_fields.php",
'../ajax/field_specific_fields.php',
[
'id' => $id,
'type' => $type,
'multiple' => '__VALUE__',
'rand' => $rand,
]
],
);
} else {
echo Html::input(
'default_value',
[
'value' => $field->fields['default_value'],
]
],
);
}
echo '</td>';
Expand Down
24 changes: 12 additions & 12 deletions ajax/reorder.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 (
!array_key_exists('container_id', $_POST)
Expand All @@ -40,9 +40,9 @@
}

$table = PluginFieldsField::getTable();
$container_id = (int)$_POST['container_id'];
$old_order = (int)$_POST['old_order'];
$new_order = (int)$_POST['new_order'];
$container_id = (int) $_POST['container_id'];
$old_order = (int) $_POST['old_order'];
$new_order = (int) $_POST['new_order'];

/** @var DBmysql $DB */
global $DB;
Expand All @@ -56,7 +56,7 @@
'plugin_fields_containers_id' => $container_id,
'ranking' => $old_order,
],
]
],
);

if (0 === $field_iterator->count()) {
Expand All @@ -75,9 +75,9 @@
],
[
'plugin_fields_containers_id' => $container_id,
['ranking' => ['>', $old_order]],
['ranking' => ['<=', $new_order]],
]
['ranking' => ['>', $old_order]],
['ranking' => ['<=', $new_order]],
],
);
} else {
$DB->update(
Expand All @@ -87,9 +87,9 @@
],
[
'plugin_fields_containers_id' => $container_id,
['ranking' => ['<', $old_order]],
['ranking' => ['>=', $new_order]],
]
['ranking' => ['<', $old_order]],
['ranking' => ['>=', $new_order]],
],
);
}

Expand All @@ -101,5 +101,5 @@
],
[
'id' => $field_id,
]
],
);
6 changes: 3 additions & 3 deletions ajax/status_override.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
* -------------------------------------------------------------------------
*/

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

if (isset($_GET['action'])) {
if ($_GET['action'] === 'get_status_dropdown') {
echo PluginFieldsStatusOverride::getStatusDropdownForItemtype($_GET['itemtype']);
} else if ($_GET['action'] === 'get_add_form') {
} elseif ($_GET['action'] === 'get_add_form') {
$status_override = new PluginFieldsStatusOverride();
$status_override->showForm(0, $_GET);
} else if ($_GET['action'] === 'get_edit_form') {
} elseif ($_GET['action'] === 'get_edit_form') {
$status_override = new PluginFieldsStatusOverride();
$status_override->getFromDB($_GET['id']);
$status_override->showForm($_GET['id'], $_GET);
Expand Down
2 changes: 1 addition & 1 deletion ajax/viewtranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/

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

Session::checkLoginUser();
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"symfony/yaml": "^5.4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"glpi-project/tools": "^0.7.4",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpstan/phpstan": "^1.12",
"squizlabs/php_codesniffer": "^3.10"
"phpstan/phpstan": "^1.12"
},
"config": {
"optimize-autoloader": true,
Expand Down
Loading

0 comments on commit db7f484

Please sign in to comment.