From 8983f524dc54818798dda2eaf19792838c5611f4 Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Mon, 14 Apr 2025 15:51:22 +0200 Subject: [PATCH] Feat(CI): TwigCS --- .twig_cs.dist.php | 15 +++++ composer.json | 6 ++ composer.lock | 59 ++++++++++++++++++- templates/computergroupstatic.html.twig | 4 +- templates/contactlog.html.twig | 8 +-- templates/credential.html.twig | 35 +++++------ templates/databaseparam.html.twig | 5 +- .../databaseparam_computergroup.html.twig | 6 +- templates/databaseparam_credential.html.twig | 4 +- 9 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 .twig_cs.dist.php diff --git a/.twig_cs.dist.php b/.twig_cs.dist.php new file mode 100644 index 0000000..352fe0a --- /dev/null +++ b/.twig_cs.dist.php @@ -0,0 +1,15 @@ +in(__DIR__ . '/templates') + ->name('*.html.twig') + ->ignoreVCSIgnored(true); + +return Twigcs\Config\Config::create() + ->setFinder($finder) + ->setRuleSet(\Glpi\Tools\GlpiTwigRuleset::class) +; diff --git a/composer.json b/composer.json index 3d0bbed..bea1b48 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.75", + "friendsoftwig/twigcs": "^6.1", "glpi-project/tools": "^0.7.4", "php-parallel-lint/php-parallel-lint": "^1.4", "phpstan/extension-installer": "^1.4", @@ -19,5 +20,10 @@ "allow-plugins": { "phpstan/extension-installer": true } + }, + "autoload-dev": { + "psr-4": { + "Glpi\\Tools\\": "../../tools/src/" + } } } diff --git a/composer.lock b/composer.lock index 5d5ea32..6080681 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6baa945ce8e1b7fee129b40b3ecef862", + "content-hash": "a120c2f6295baba8513207928680cfca", "packages": [], "packages-dev": [ { @@ -509,6 +509,61 @@ ], "time": "2025-03-31T18:40:42+00:00" }, + { + "name": "friendsoftwig/twigcs", + "version": "v6.1.0", + "source": { + "type": "git", + "url": "https://github.com/friendsoftwig/twigcs.git", + "reference": "3c36d606c4f19db0dd2a01b735ec7a8151b7f182" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/friendsoftwig/twigcs/zipball/3c36d606c4f19db0dd2a01b735ec7a8151b7f182", + "reference": "3c36d606c4f19db0dd2a01b735ec7a8151b7f182", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-hash": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", + "symfony/console": "^4.4 || ^5.3 || ^6.0", + "symfony/filesystem": "^4.4 || ^5.3 || ^6.0", + "symfony/finder": "^4.4 || ^5.3 || ^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.20", + "symfony/phpunit-bridge": "^6.2.3" + }, + "bin": [ + "bin/twigcs" + ], + "type": "library", + "autoload": { + "psr-4": { + "FriendsOfTwig\\Twigcs\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tristan Maindron", + "email": "tmaindron@gmail.com" + } + ], + "description": "Checkstyle automation for Twig", + "support": { + "issues": "https://github.com/friendsoftwig/twigcs/issues", + "source": "https://github.com/friendsoftwig/twigcs/tree/v6.1.0" + }, + "time": "2023-01-04T16:01:24+00:00" + }, { "name": "glpi-project/tools", "version": "0.7.4", @@ -2984,5 +3039,5 @@ "platform-overrides": { "php": "7.4.99" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/templates/computergroupstatic.html.twig b/templates/computergroupstatic.html.twig index db47e97..10272cd 100644 --- a/templates/computergroupstatic.html.twig +++ b/templates/computergroupstatic.html.twig @@ -60,7 +60,7 @@ {{ fields.hiddenField( 'plugin_databaseinventory_computergroups_id', item.getID(), - )}} + ) }} {% endif %} @@ -103,7 +103,7 @@ {% if checked %}checked="checked"{% endif %}> {% endif %} - {{ computer['name'] }} + {{ computer['name'] }} {% if computer['is_dynamic'] == 1 %} {% set is_dynamic = __('Yes') %} {% else %} diff --git a/templates/contactlog.html.twig b/templates/contactlog.html.twig index ac27926..1157f00 100644 --- a/templates/contactlog.html.twig +++ b/templates/contactlog.html.twig @@ -26,8 +26,6 @@ # ------------------------------------------------------------------------- #} -{% import "components/form/fields_macros.html.twig" as fields %} - {% block more_fields %} {% if canread %} {% if contactlogs is not empty %} @@ -46,11 +44,11 @@ {{ tableheader }} {% for contactlog in contactlogs %} - {{ contactlog['credname'] }} + {{ contactlog['credname'] }} {% if itemtype == 'Agent' %} - {{ contactlog['dbparamname'] }} + {{ contactlog['dbparamname'] }} {% else %} - {{ contactlog['agentname'] }} + {{ contactlog['agentname'] }} {% endif %} {{ contactlog['date_creation']|formatted_datetime }} diff --git a/templates/credential.html.twig b/templates/credential.html.twig index 30a3205..0abccc4 100644 --- a/templates/credential.html.twig +++ b/templates/credential.html.twig @@ -36,27 +36,24 @@ item.fields['port'], __('Port', 'databaseinventory'), {'min' : 0, 'max' : 99999, 'step' : 1} - )}} + ) }} {{ fields.textField( - 'login', - item.fields['login'], - __('Login', 'databaseinventory'), - ) - }} + 'login', + item.fields['login'], + __('Login', 'databaseinventory'), + ) }} - {{ fields.passwordField( - 'password', - item.fields['password'], - __('Password', 'databaseinventory'), - {'clearable': true, 'is_disclosable' : false} - ) - }} - {{ fields.textField( - 'socket', - item.fields['socket'], - __('Socket', 'databaseinventory'), - ) - }} + {{ fields.passwordField( + 'password', + item.fields['password'], + __('Password', 'databaseinventory'), + {'clearable': true, 'is_disclosable' : false} + ) }} + {{ fields.textField( + 'socket', + item.fields['socket'], + __('Socket', 'databaseinventory'), + ) }} {% endblock %} diff --git a/templates/databaseparam.html.twig b/templates/databaseparam.html.twig index a6de483..d8a5efd 100644 --- a/templates/databaseparam.html.twig +++ b/templates/databaseparam.html.twig @@ -35,14 +35,13 @@ 'partial_inventory', item.fields['partial_inventory'], __('Execution frequency for partial inventory', 'databaseinventory'), - ) - }} + ) }} {{ fields.dropdownNumberField( 'execution_delay', item.fields['execution_delay'], __('Execution delay', 'databaseinventory'), {'min' : 0, 'max' : 24, 'step' : 1, 'unit' : 'hour'} - )}} + ) }} {% endblock %} \ No newline at end of file diff --git a/templates/databaseparam_computergroup.html.twig b/templates/databaseparam_computergroup.html.twig index 4561596..c279036 100644 --- a/templates/databaseparam_computergroup.html.twig +++ b/templates/databaseparam_computergroup.html.twig @@ -47,7 +47,7 @@ {% set btn_add %} {% endset %} @@ -60,7 +60,7 @@ {{ fields.hiddenField( 'plugin_databaseinventory_databaseparams_id', item.getID(), - )}} + ) }} {% endif %} @@ -102,7 +102,7 @@ {% if checked %}checked="checked"{% endif %}> {% endif %} - {{ compgroup['name'] }} + {{ compgroup['name'] }} {{ compgroup['comment'] }} {{ compgroup['nbdynamicitems'] }} {{ compgroup['nbstaticitems'] }} diff --git a/templates/databaseparam_credential.html.twig b/templates/databaseparam_credential.html.twig index 9851095..2c2bb30 100644 --- a/templates/databaseparam_credential.html.twig +++ b/templates/databaseparam_credential.html.twig @@ -60,7 +60,7 @@ {{ fields.hiddenField( 'plugin_databaseinventory_databaseparams_id', item.getID(), - )}} + ) }} {% endif %} @@ -102,7 +102,7 @@ {% if checked %}checked="checked"{% endif %}> {% endif %} - {{ credential['name'] }} + {{ credential['name'] }} {{ credential['login'] }} {{ credential['port'] }} {{ credential['socket'] }}