Skip to content

Commit

Permalink
minor #42010 Improve usage of twig ternary (Seb33300)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

Improve usage of twig ternary

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | none
| License       | MIT
| Doc PR        | none

Remove useless `else` condition when using twig ternary:

> `{{ foo ? 'yes' }}` is the same as `{{ foo ? 'yes' : '' }}`

See: https://twig.symfony.com/doc/3.x/templates.html#other-operators

Commits
-------

4be962d323 Improve usage of twig ternary
  • Loading branch information
fabpot committed Jul 24, 2021
2 parents 236017d + a7adf96 commit 10db99e
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Resources/views/Collector/config.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
{% endblock %}

{% block menu %}
<span class="label label-status-{{ collector.symfonyState == 'eol' ? 'red' : collector.symfonyState in ['eom', 'dev'] ? 'yellow' : '' }}">
<span class="label label-status-{{ collector.symfonyState == 'eol' ? 'red' : collector.symfonyState in ['eom', 'dev'] ? 'yellow' }}">
<span class="icon">{{ include('@WebProfiler/Icon/config.svg') }}</span>
<strong>Configuration</strong>
</span>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Collector/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block toolbar %}
{% if collector.data.nb_errors > 0 or collector.data.forms|length %}
{% set status_color = collector.data.nb_errors ? 'red' : '' %}
{% set status_color = collector.data.nb_errors ? 'red' %}
{% set icon %}
{{ include('@WebProfiler/Icon/form.svg') }}
<span class="sf-toolbar-value">
Expand Down
6 changes: 3 additions & 3 deletions Resources/views/Collector/logger.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@

<tbody>
{% for log in logs %}
{% set css_class = is_deprecation ? ''
: log.priorityName in ['CRITICAL', 'ERROR', 'ALERT', 'EMERGENCY'] ? 'status-error'
{% set css_class = not is_deprecation
? log.priorityName in ['CRITICAL', 'ERROR', 'ALERT', 'EMERGENCY'] ? 'status-error'
: log.priorityName == 'WARNING' ? 'status-warning'
%}
<tr class="{{ css_class }}"{% if show_level %} data-filter-level="{{ log.priorityName|lower }}"{% endif %}{% if channel_is_defined %} data-filter-channel="{{ log.channel is not null ? log.channel : '' }}"{% endif %}>
<tr class="{{ css_class }}"{% if show_level %} data-filter-level="{{ log.priorityName|lower }}"{% endif %}{% if channel_is_defined %} data-filter-channel="{{ log.channel }}"{% endif %}>
<td class="font-normal text-small" nowrap>
{% if show_level %}
<span class="colored text-bold">{{ log.priorityName }}</span>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Collector/mailer.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{% block menu %}
{% set events = collector.events %}

<span class="label {{ events.messages|length ? '' : 'disabled' }}">
<span class="label {{ events.messages|empty ? 'disabled' }}">
<span class="icon">{{ include('@WebProfiler/Icon/mailer.svg') }}</span>

<strong>E-mails</strong>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Collector/memory.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block toolbar %}
{% set icon %}
{% set status_color = (collector.memory / 1024 / 1024) > 50 ? 'yellow' : '' %}
{% set status_color = (collector.memory / 1024 / 1024) > 50 ? 'yellow' %}
{{ include('@WebProfiler/Icon/memory.svg') }}
<span class="sf-toolbar-value">{{ '%.1f'|format(collector.memory / 1024 / 1024) }}</span>
<span class="sf-toolbar-label">MiB</span>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Collector/time.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% set has_time_events = collector.events|length > 0 %}
{% set total_time = has_time_events ? '%.0f'|format(collector.duration) : 'n/a' %}
{% set initialization_time = collector.events|length ? '%.0f'|format(collector.inittime) : 'n/a' %}
{% set status_color = has_time_events and collector.duration > 1000 ? 'yellow' : '' %}
{% set status_color = has_time_events and collector.duration > 1000 ? 'yellow' %}

{% set icon %}
{{ include('@WebProfiler/Icon/time.svg') }}
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Collector/validator.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block toolbar %}
{% if collector.violationsCount > 0 or collector.calls|length %}
{% set status_color = collector.violationsCount ? 'red' : '' %}
{% set status_color = collector.violationsCount ? 'red' %}
{% set icon %}
{{ include('@WebProfiler/Icon/validator.svg') }}
<span class="sf-toolbar-value">
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Profiler/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
{%- endif -%}
{%- endset %}
{% if menu is not empty %}
<li class="{{ name }} {{ name == panel ? 'selected' : '' }}">
<li class="{{ name }} {{ name == panel ? 'selected' }}">
<a href="{{ path('_profiler', { token: token, panel: name }) }}">{{ menu|raw }}</a>
</li>
{% endif %}
Expand Down

0 comments on commit 10db99e

Please sign in to comment.