Skip to content

Commit de37ab7

Browse files
stonebuzzRom1-B
andauthored
Feat(Build) add REctor (#1029)
* Feat(Build) add REctor * fix * Update ajax/container.php Co-authored-by: Romain B. <[email protected]> * Update ajax/reorder.php Co-authored-by: Romain B. <[email protected]> * Update inc/labeltranslation.class.php Co-authored-by: Romain B. <[email protected]> * Update inc/profile.class.php Co-authored-by: Romain B. <[email protected]> * Update inc/toolbox.class.php Co-authored-by: Romain B. <[email protected]> * fix * Apply suggestion from @Rom1-B --------- Co-authored-by: Romain B. <[email protected]>
1 parent 87d0684 commit de37ab7

30 files changed

+383
-350
lines changed

.twig_cs.dist.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
declare(strict_types=1);
44

5-
use FriendsOfTwig\Twigcs;
5+
use FriendsOfTwig\Twigcs\Finder\TemplateFinder;
6+
use FriendsOfTwig\Twigcs\Config\Config;
7+
use Glpi\Tools\GlpiTwigRuleset;
68

7-
$finder = Twigcs\Finder\TemplateFinder::create()
9+
$finder = TemplateFinder::create()
810
->in(__DIR__ . '/templates')
911
->name('*.html.twig')
1012
->ignoreVCSIgnored(true);
1113

12-
return Twigcs\Config\Config::create()
14+
return Config::create()
1315
->setFinder($finder)
14-
->setRuleSet(\Glpi\Tools\GlpiTwigRuleset::class)
16+
->setRuleSet(GlpiTwigRuleset::class)
1517
;

ajax/container.php

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

31-
include('../../../inc/includes.php');
32-
Session::checkLoginUser();
31+
use Glpi\Exception\Http\AccessDeniedHttpException;
32+
use Glpi\Exception\Http\NotFoundHttpException;
3333

34+
Session::checkLoginUser();
3435

3536
if (isset($_GET['action']) && $_GET['action'] === 'get_fields_html') {
3637

3738
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $_GET['id']);
3839
if ($right < READ) {
39-
throw new \Glpi\Exception\Http\AccessDeniedHttpException();
40+
throw new AccessDeniedHttpException();
4041
}
4142

4243
$containers_id = $_GET['id'];
@@ -49,7 +50,7 @@
4950
$dbu = new DbUtils();
5051
$item = $dbu->getItemForItemtype($itemtype);
5152
if ($items_id > 0 && !$item->getFromDB($items_id)) {
52-
throw new \Glpi\Exception\Http\NotFoundHttpException();
53+
throw new NotFoundHttpException();
5354
}
5455
$item->input = $input;
5556

@@ -65,5 +66,5 @@
6566
echo '';
6667
}
6768
} else {
68-
throw new \Glpi\Exception\Http\NotFoundHttpException();
69+
throw new NotFoundHttpException();
6970
}

ajax/container_display_condition.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
* @link https://github.com/pluginsGLPI/fields
2828
* -------------------------------------------------------------------------
2929
*/
30-
31-
include('../../../inc/includes.php');
3230
Session::checkLoginUser();
3331

3432
if (isset($_GET['action'])) {
@@ -55,5 +53,5 @@
5553
}
5654
}
5755
} else {
58-
throw new \RuntimeException('Invalid request', 400);
56+
throw new RuntimeException('Invalid request', 400);
5957
}

ajax/container_itemtypes_dropdown.php

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

31-
include('../../../inc/includes.php');
3231
Session::checkLoginUser();
3332

3433
PluginFieldsContainer::showFormItemtype($_REQUEST);

ajax/container_subtype_dropdown.php

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

31-
include('../../../inc/includes.php');
3231
Session::checkLoginUser();
3332

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

ajax/field_specific_fields.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
* -------------------------------------------------------------------------
3232
*/
3333

34-
include('../../../inc/includes.php');
3534
header('Content-Type: text/html; charset=UTF-8');
3635
Html::header_nocache();
3736
Session::checkLoginUser();
@@ -66,11 +65,9 @@
6665
echo implode(
6766
', ',
6867
array_map(
69-
function ($itemtype) {
70-
return is_a($itemtype, CommonDBTM::class, true)
71-
? $itemtype::getTypeName(Session::getPluralNumber())
72-
: $itemtype;
73-
},
68+
fn($itemtype) => is_a($itemtype, CommonDBTM::class, true)
69+
? $itemtype::getTypeName(Session::getPluralNumber())
70+
: $itemtype,
7471
$allowed_itemtypes,
7572
),
7673
);

ajax/reorder.php

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

31-
include('../../../inc/includes.php');
31+
use Glpi\DBAL\QueryExpression;
32+
3233
Session::checkLoginUser();
3334

3435
if (
@@ -37,7 +38,7 @@
3738
|| !array_key_exists('new_order', $_POST)
3839
) {
3940
// Missing input
40-
throw new \RuntimeException('Missing input', 400);
41+
throw new RuntimeException('Missing input', 400);
4142
}
4243

4344
$table = PluginFieldsField::getTable();
@@ -62,7 +63,7 @@
6263

6364
if (0 === $field_iterator->count()) {
6465
// Unknown field
65-
throw new \RuntimeException('Unknown field', 404);
66+
throw new RuntimeException('Unknown field', 404);
6667
}
6768

6869
$field_id = $field_iterator->current()['id'];
@@ -72,7 +73,7 @@
7273
$DB->update(
7374
$table,
7475
[
75-
'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' - 1'),
76+
'ranking' => new QueryExpression($DB->quoteName('ranking') . ' - 1'),
7677
],
7778
[
7879
'plugin_fields_containers_id' => $container_id,
@@ -84,7 +85,7 @@
8485
$DB->update(
8586
$table,
8687
[
87-
'ranking' => new \Glpi\DBAL\QueryExpression($DB->quoteName('ranking') . ' + 1'),
88+
'ranking' => new QueryExpression($DB->quoteName('ranking') . ' + 1'),
8889
],
8990
[
9091
'plugin_fields_containers_id' => $container_id,

ajax/status_override.php

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

31-
include('../../../inc/includes.php');
3231
Session::checkLoginUser();
3332

3433
if (isset($_GET['action'])) {
@@ -43,5 +42,5 @@
4342
$status_override->showForm($_GET['id'], $_GET);
4443
}
4544
} else {
46-
throw new \RuntimeException('Invalid request', 400);
45+
throw new RuntimeException('Invalid request', 400);
4746
}

ajax/viewtranslations.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,17 @@
3232
* @brief
3333
*/
3434

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

3938
Session::checkLoginUser();
4039

4140
if (!isset($_POST['itemtype']) || !isset($_POST['items_id']) || !isset($_POST['id'])) {
42-
throw new \RuntimeException('Missing required parameters', 400);
41+
throw new RuntimeException('Missing required parameters', 400);
4342
}
4443

4544
$translation = new PluginFieldsLabelTranslation();
46-
if ($_POST['id'] == -1) {
47-
$canedit = $translation->can(-1, CREATE, $_POST);
48-
} else {
49-
$canedit = $translation->can($_POST['id'], UPDATE);
50-
}
45+
$canedit = $_POST['id'] == -1 ? $translation->can(-1, CREATE, $_POST) : $translation->can($_POST['id'], UPDATE);
5146
if ($canedit) {
5247
$translation->showFormForItem($_POST['itemtype'], $_POST['items_id'], $_POST['id']);
5348
} else {

front/container.php

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

31-
include('../../../inc/includes.php');
3231
Session::checkLoginUser();
3332

3433
Html::header(

0 commit comments

Comments
 (0)