Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #276: Implemented Twig CS checker/fixer. #279

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ clover.xml
coveralls-upload.json
.phpunit.result.cache
.phpcs-cache
.twig-cs-fixer.cache

# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"mezzio/mezzio-tooling": "^2.9.0",
"phpunit/phpunit": "^10.5.9",
"roave/security-advisories": "dev-latest",
"vimeo/psalm": "^5.20.0"
"vimeo/psalm": "^5.20.0",
"vincentlanglet/twig-cs-fixer": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -97,6 +98,8 @@
"serve": "php -S 0.0.0.0:8080 -t public/",
"static-analysis": "psalm --shepherd --stats",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"twig-cs-check": "vendor/bin/twig-cs-fixer lint --config=config/twig-cs-fixer.php",
"twig-cs-fix": "vendor/bin/twig-cs-fixer lint --config=config/twig-cs-fixer.php --fix"
}
}
9 changes: 9 additions & 0 deletions config/twig-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

$config = new TwigCsFixer\Config\Config();
$config->addTwigExtension(new Dot\Twig\Extension\DateExtension());
$config->addTwigExtension(new Dot\Twig\Extension\TranslationExtension());

return $config;
12 changes: 6 additions & 6 deletions src/Admin/templates/admin/account.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}
<div class="row m-5">
{{ messagesPartial('partial::alerts', { dismissible: true }) }}
{{ messagesPartial('partial::alerts', {dismissible: true}) }}
</div>
<div class="row gap-20 masonry pos-r">
<div class="masonry-sizer col-md-6"></div>
Expand All @@ -14,7 +14,7 @@
<div class="mT-30">

{% set dummy = form.prepare() %}
{{ form().openTag(form) | raw }}
{{ form().openTag(form)|raw }}

{% set identity = form.getElements().identity %}
<div class="mb-3 form-group {% if identity.getMessages() %}has-error{% endif %}">
Expand Down Expand Up @@ -43,7 +43,7 @@
{% set dummy = submit.setAttribute('class', 'btn btn-primary btn-color') %}
{{ formSubmit(submit) }}

{{ form().closeTag() | raw }}
{{ form().closeTag()|raw }}
</div>
</div>
</div>
Expand All @@ -52,8 +52,8 @@
<h6 class="c-grey-900">Change password</h6>
<div class="mT-30">
{% set dummy = changePasswordForm.prepare() %}
{% set dummy = changePasswordForm.setAttribute('action', path('admin', { action : "change-password" })) %}
{{ form().openTag(changePasswordForm) | raw }}
{% set dummy = changePasswordForm.setAttribute('action', path('admin', {action: 'change-password'})) %}
{{ form().openTag(changePasswordForm)|raw }}

{% set currentPassword = changePasswordForm.get('currentPassword') %}
<div class="mb-3 form-group {% if currentPassword.getMessages() %}has-error{% endif %}">
Expand Down Expand Up @@ -82,7 +82,7 @@
{% set dummy = submit.setAttribute('class', 'btn btn-primary btn-color') %}
{{ formSubmit(submit) }}

{{ form().closeTag() | raw }}
{{ form().closeTag()|raw }}
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/templates/admin/delete.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ form().openTag(form) | raw }}
{{ form().openTag(form)|raw }}
<p>Are you sure you want to delete admin account with identity <span id="adminIdentity" class="fw-bold">{{ admin.identity }}</span>?</p>
<div class="form-check">
{{ formElement(form.get('confirmation')) }}
<label class="form-check-label" for="confirmation">Yes, I want to delete <span class="fw-bold">{{ admin.identity }}</span></label>
</div>
{{ formElement(form.get('adminDeleteCsrf')) }}
{{ form().closeTag() | raw }}
{{ form().closeTag()|raw }}
1 change: 0 additions & 1 deletion src/Admin/templates/admin/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@
</div>
</div>
{% endblock %}

4 changes: 2 additions & 2 deletions src/Admin/templates/admin/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
<div class="col-md-4">
{% set dummy = form.prepare() %}
{{ form().openTag(form) | raw }}
{{ form().openTag(form)|raw }}
<h4 class="fw-300 c-grey-900 mB-20">Login</h4>
<div class="mb-3">
{% set username = form.get('username') %}
Expand All @@ -45,7 +45,7 @@

{{ formSubmit(submit) }}

{{ form().closeTag() | raw }}
{{ form().closeTag()|raw }}
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/App/templates/layout/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<![endif]-->
</head>
<body class="app">
{% include '@partial/left-menu.html.twig' %}
{{ include('@partial/left-menu.html.twig') }}
<div class="page-container">
{% include '@partial/nav-bar.html.twig' %}
{{ include('@partial/nav-bar.html.twig') }}
<main class='main-content bgc-grey-100'>
<div id='mainContent'>
{% block content %}{% endblock %}
Expand Down
6 changes: 3 additions & 3 deletions src/App/templates/partial/ajax-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% set dummy = form.setAttribute('action', formAction) %}
{% set dummy = form.prepare() %}

{{ form().openTag(form) | raw }}
{% include '@partial/form-display-elements.html.twig' with {'form' : form, 'showLabels' : true} only %}
{{ form().closeTag() | raw }}
{{ form().openTag(form)|raw }}
{{ include('@partial/form-display-elements.html.twig', {form: form, showLabels: true}, false) }}
{{ form().closeTag()|raw }}

<script type="application/javascript">
$(document).ready(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/App/templates/partial/alerts.html.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{% set classes = {'error': 'danger', 'info': 'info', 'warning': 'warning', 'success' : 'success'} %}
{% set classes = {error: 'danger', info: 'info', warning: 'warning', success: 'success'} %}
{% if dismissible is not defined %}
{% set dismissible = false %}
{% endif %}


{% if messages is defined and messages is iterable %}
{% for namespace in messages|keys %}
{% if classes[namespace] is defined %}
Expand Down
6 changes: 3 additions & 3 deletions src/App/templates/partial/form-display-elements.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set showLabels = false %}
{% endif %}

{% for k,v in form.getElements() %}
{% for k, v in form.getElements() %}
{% set element = form.get(k) %}
{% if element is Captcha %}
<div class="mb-3">
Expand All @@ -17,7 +17,7 @@
</div>
{% elseif element is MultiCheckbox %}
{% set dummy = element.setAttribute('class', 'form-check-input') %}
{% set dummy = element.setLabelAttributes([]|merge({'class': 'form-label mR-25'})) %}
{% set dummy = element.setLabelAttributes([]|merge({class: 'form-label mR-25'})) %}

<div class="form-check gap-10">
{{ formElement(element) }}
Expand Down Expand Up @@ -49,7 +49,7 @@
<div class="mb-3 {% if element.getMessages() %}has-error{% endif %}">

{% set dummy = element.setAttribute('class', 'form-control') %}
{% set dummy = element.setLabelAttributes([]|merge({'class': 'form-label'})) %}
{% set dummy = element.setLabelAttributes([]|merge({class: 'form-label'})) %}

{% if showLabels and element.getLabel() is defined and element.getLabel() is not empty %}
{{ formLabel(element) }}
Expand Down
6 changes: 3 additions & 3 deletions src/App/templates/partial/left-menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@
</a>
<ul class="dropdown-menu">
<li class="nav-item dropdown">
<a href="{{ path('admin', { action : 'manage' }) }}">
<a href="{{ path('admin', {action: 'manage'}) }}">
<span>List</span>
</a>
</li>
<li class="nav-item dropdown">
<a href="{{ path('admin', { action : 'logins' }) }}">
<a href="{{ path('admin', {action: 'logins'}) }}">
<span>View logins</span>
</a>
</li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="sidebar-link" href="{{ path('page', { action : 'components' }) }}">
<a class="sidebar-link" href="{{ path('page', {action: 'components'}) }}">
<span class="icon-holder">
<i class="c-pink-500 ti-palette"></i>
</span>
Expand Down
4 changes: 1 addition & 3 deletions src/App/templates/partial/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@
{% endif %}
{% endif %}



{% if page.hasChildren() %}
{% set subitemUlClass = 'children collapse' %}
{% if navigation.isActive(page) %}
{% set subitemUlClass = subitemUlClass ~ ' in' %}
{% endif %}

{% set ulId = 'sub-item-' ~ loop.index %}
{{ navigationPartial(page, 'partial::menu', {'ulClass' : subitemUlClass, 'ulId': ulId, 'depth' : depth + 1}) }}
{{ navigationPartial(page, 'partial::menu', {ulClass: subitemUlClass, ulId: ulId, depth: depth + 1}) }}

{% endif %}

Expand Down
4 changes: 2 additions & 2 deletions src/App/templates/partial/nav-bar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
</a>
<ul class="dropdown-menu fsz-sm">
<li>
<a href="{{ path('admin', { action : "account" }) }}" class="d-b td-n pY-5 bgcH-grey-100 c-grey-700">
<a href="{{ path('admin', {action: 'account'}) }}" class="d-b td-n pY-5 bgcH-grey-100 c-grey-700">
<i class="ti-user mR-10"></i>
<span>Profile</span>
</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="{{ path('admin', { action : "logout" }) }}" class="d-b td-n pY-5 bgcH-grey-100 c-grey-700">
<a href="{{ path('admin', {action: 'logout'}) }}" class="d-b td-n pY-5 bgcH-grey-100 c-grey-700">
<i class="ti-power-off mR-10"></i>
<span>Logout</span>
</a>
Expand Down
Loading