Skip to content

Commit

Permalink
Fix Twig code style
Browse files Browse the repository at this point in the history
  • Loading branch information
ruudk committed Nov 5, 2024
1 parent e058b9b commit 6a3415b
Show file tree
Hide file tree
Showing 28 changed files with 96 additions and 100 deletions.
6 changes: 3 additions & 3 deletions tests/EndToEnd/Filters/array.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ https://twig.symfony.com/doc/3.x/filters/batch.html

https://twig.symfony.com/doc/3.x/filters/column.html
\Twig\Extension\CoreExtension::column
{% assert_type [{name: 'John'}, {name: 'Jane'}] | column('name') "array{'John', 'Jane'}" %}
{% assert_type [{ name: 'John' }, { name: 'Jane' }] | column('name') "array{'John', 'Jane'}" %}

https://twig.symfony.com/doc/3.x/filters/filter.html
\Twig\Extension\CoreExtension::filter
Expand All @@ -35,8 +35,8 @@ https://twig.symfony.com/doc/3.x/filters/filter.html
https://twig.symfony.com/doc/3.x/filters/map.html
\Twig\Extension\CoreExtension::map
{% assert_type [
{first: "John", last: "Doe"},
{first: "Jane", last: "Doe"},
{ first: 'John', last: 'Doe' },
{ first: 'Jane', last: 'Doe' },
] | map(p => "#{p.first} #{p.last}") 'array<0|1, non-falsy-string>' %}

https://twig.symfony.com/doc/3.x/filters/reduce.html
Expand Down
4 changes: 2 additions & 2 deletions tests/EndToEnd/Filters/encoding.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
https://twig.symfony.com/doc/3.x/filters/url_encode.html
\Twig\Extension\CoreExtension::urlencode
{% assert_type 'Hello' | url_encode 'string' %}
{% assert_type {'name': 'Fabien', 'city': 'Paris'} | url_encode 'string' %}
{% assert_type { name: 'Fabien', city: 'Paris' } | url_encode 'string' %}

https://twig.symfony.com/doc/3.x/filters/json_encode.html
\Twig\Extension\CoreExtension::json_encode
Expand All @@ -10,4 +10,4 @@ https://twig.symfony.com/doc/3.x/filters/json_encode.html

https://twig.symfony.com/doc/3.x/filters/convert_encoding.html
\Twig\Extension\CoreExtension::convertEncoding
{% assert_type data|convert_encoding('UTF-8', 'iso-2022-jp') 'string' %}
{% assert_type data | convert_encoding('UTF-8', 'iso-2022-jp') 'string' %}
20 changes: 10 additions & 10 deletions tests/EndToEnd/Filters/formatting.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@

https://twig.symfony.com/doc/3.x/filters/date.html
\Twig\Extension\CoreExtension::formatDate
{% assert_type "now" | date("m/d/Y") 'string' %}
{% assert_type dateTime | date("m/d/Y") 'string' %}
{% assert_type dateTimeImmutable | date("m/d/Y") 'string' %}
{% assert_type dateTimeInterface | date("m/d/Y") 'string' %}
{% assert_type 'now' | date('m/d/Y') 'string' %}
{% assert_type dateTime | date('m/d/Y') 'string' %}
{% assert_type dateTimeImmutable | date('m/d/Y') 'string' %}
{% assert_type dateTimeInterface | date('m/d/Y') 'string' %}

https://twig.symfony.com/doc/3.x/filters/date_modify.html
\Twig\Extension\CoreExtension::modifyDate
{% assert_type "now" | date_modify("+1 day") 'DateTime' %}
{% assert_type dateTime | date_modify("+1 day") 'DateTime' %}
{% assert_type dateTimeImmutable | date_modify("+1 day") 'DateTimeImmutable' %}
{% assert_type dateTimeInterface | date_modify("+1 day") 'DateTimeInterface' %}
{% assert_type 'now' | date_modify('+1 day') 'DateTime' %}
{% assert_type dateTime | date_modify('+1 day') 'DateTime' %}
{% assert_type dateTimeImmutable | date_modify('+1 day') 'DateTimeImmutable' %}
{% assert_type dateTimeInterface | date_modify('+1 day') 'DateTimeInterface' %}

https://twig.symfony.com/doc/3.x/filters/format.html
\Twig\Extension\CoreExtension::sprintf
{% assert_type "I like %s and %s." | format('apples', 'oranges') "'I like apples and oranges.'" %}
{% assert_type 'I like %s and %s.' | format('apples', 'oranges') "'I like apples and oranges.'" %}

https://twig.symfony.com/doc/3.x/filters/replace.html
\Twig\Extension\CoreExtension::replace
{% assert_type "I like %this% and %that%." | replace({'%this%': fruit, '%that%': "oranges"}) 'string' %}
{% assert_type 'I like %this% and %that%.' | replace({ '%this%': fruit, '%that%': 'oranges' }) 'string' %}

https://twig.symfony.com/doc/3.x/filters/number_format.html
\Twig\Extension\CoreExtension::formatNumber
Expand Down
2 changes: 1 addition & 1 deletion tests/EndToEnd/Filters/iteration_runtime.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ https://twig.symfony.com/doc/3.x/filters/default.html
https://twig.symfony.com/doc/3.x/filters/keys.html
\Twig\Extension\CoreExtension::keys
{% assert_type [1, 2, 3, 4] | keys 'array{0, 1, 2, 3}' %}
{% assert_type {a: 'aa', b: 'bb'} | keys "array{'a', 'b'}" %}
{% assert_type { a: 'aa', b: 'bb' } | keys "array{'a', 'b'}" %}
4 changes: 2 additions & 2 deletions tests/EndToEnd/Filters/string.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ https://twig.symfony.com/doc/3.x/filters/lower.html

https://twig.symfony.com/doc/3.x/filters/striptags.html
\Twig\Extension\CoreExtension::striptags
{% assert_type 'html' | striptags "string" %}
{% assert_type 'html' | striptags 'string' %}

https://twig.symfony.com/doc/3.x/filters/nl2br.html
\Twig\Extension\CoreExtension::nl2br
{% assert_type 'Hello\nWorld' | nl2br "string" %}
{% assert_type 'Hello\nWorld' | nl2br 'string' %}
8 changes: 4 additions & 4 deletions tests/EndToEnd/Filters/string.twig3
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
https://twig.symfony.com/doc/3.x/filters/trim.html
\Twig\Extension\CoreExtension::trim
{% assert_type ' I like Twig. '|trim "string" %}
{% assert_type ' I like Twig.'|trim('.') "string" %}
{% assert_type ' I like Twig. '|trim(side: 'left') "string" %}
{% assert_type ' I like Twig. '|trim(' ', 'right') "string" %}
{% assert_type ' I like Twig. ' | trim 'string' %}
{% assert_type ' I like Twig.' | trim('.') 'string' %}
{% assert_type ' I like Twig. ' | trim(side: 'left') 'string' %}
{% assert_type ' I like Twig. ' | trim(' ', 'right') 'string' %}
8 changes: 4 additions & 4 deletions tests/EndToEnd/Filters/string.twig4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
https://twig.symfony.com/doc/3.x/filters/trim.html
\Twig\Extension\CoreExtension::trim
{% assert_type ' I like Twig. '|trim "string|Stringable" %}
{% assert_type ' I like Twig.'|trim('.') "string|Stringable" %}
{% assert_type ' I like Twig. '|trim(side: 'left') "string|Stringable" %}
{% assert_type ' I like Twig. '|trim(' ', 'right') "string|Stringable" %}
{% assert_type ' I like Twig. ' | trim 'string|Stringable' %}
{% assert_type ' I like Twig.' | trim('.') 'string|Stringable' %}
{% assert_type ' I like Twig. ' | trim(side: 'left') 'string|Stringable' %}
{% assert_type ' I like Twig. ' | trim(' ', 'right') 'string|Stringable' %}
26 changes: 13 additions & 13 deletions tests/EndToEnd/Filters/string_array.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
https://twig.symfony.com/doc/3.x/filters/reverse.html
\Twig\Extension\CoreExtension::reverse
{% assert_type ['a', 'b'] | reverse "array{'b', 'a'}" %}
{% assert_type array | reverse "array<string>" %}
{% assert_type "Hello" | reverse "string" %}
{% assert_type array | reverse 'array<string>' %}
{% assert_type 'Hello' | reverse 'string' %}

https://twig.symfony.com/doc/3.x/filters/shuffle.html
\Twig\Extension\CoreExtension::shuffle
{% assert_type ['a', 'b'] | shuffle "non-empty-array<0|1, 'a'|'b'>&list" %}
{% assert_type array | shuffle "list<string>" %}
{% assert_type "Hello" | shuffle "string" %}
{% assert_type array | shuffle 'list<string>' %}
{% assert_type 'Hello' | shuffle 'string' %}

https://twig.symfony.com/doc/3.x/filters/length.html
\Twig\Extension\CoreExtension::length
{% assert_type ['a', 'b'] | length "int" %}
{% assert_type array | length "int" %}
{% assert_type "Hello" | length "int" %}
{% assert_type ['a', 'b'] | length 'int' %}
{% assert_type array | length 'int' %}
{% assert_type 'Hello' | length 'int' %}

https://twig.symfony.com/doc/3.x/filters/slice.html
\Twig\Extension\CoreExtension::slice
{% assert_type ['a', 'b'] | slice(1, 2) "array{'b'}" %}
{% assert_type array | slice(1, 2) "array<string>" %}
{% assert_type "Hello" | slice(0, 2) "'He'" %}
{% assert_type array | slice(1, 2) 'array<string>' %}
{% assert_type 'Hello' | slice(0, 2) "'He'" %}

https://twig.symfony.com/doc/3.x/filters/first.html
\Twig\Extension\CoreExtension::first
{% assert_type ['a', 'b'] | first "'a'" %}
{% assert_type array | first "string" %}
{% assert_type "Hello" | first "'H'" %}
{% assert_type array | first 'string' %}
{% assert_type 'Hello' | first "'H'" %}

https://twig.symfony.com/doc/3.x/filters/last.html
\Twig\Extension\CoreExtension::last
{% assert_type ['a', 'b'] | last "'b'" %}
{% assert_type array | last "string" %}
{% assert_type "Hello" | last "'o'" %}
{% assert_type array | last 'string' %}
{% assert_type 'Hello' | last "'o'" %}
14 changes: 7 additions & 7 deletions tests/EndToEnd/Functions/functions.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
https://twig.symfony.com/doc/3.x/functions/min.html
{% assert_type min(1, 3, 2) "1" %}
{% assert_type min([1, 3, 2]) "1" %}
{% assert_type min({2: "e", 3: "a", 1: "b", 5: "d", 4: "c"}) "'a'" %}
{% assert_type min(1, 3, 2) '1' %}
{% assert_type min([1, 3, 2]) '1' %}
{% assert_type min({ 2: 'e', 3: 'a', 1: 'b', 5: 'd', 4: 'c' }) "'a'" %}

https://twig.symfony.com/doc/3.x/functions/max.html
{% assert_type max(1, 3, 2) "3" %}
{% assert_type max([1, 3, 2]) "3" %}
{% assert_type max({2: "e", 3: "a", 1: "b", 5: "d", 4: "c"}) "'e'" %}
{% assert_type max(1, 3, 2) '3' %}
{% assert_type max([1, 3, 2]) '3' %}
{% assert_type max({ 2: 'e', 3: 'a', 1: 'b', 5: 'd', 4: 'c' }) "'e'" %}

https://twig.symfony.com/doc/3.x/functions/range.html
{% assert_type range(0, 6, 2) "array{0, 2, 4, 6}" %}
{% assert_type range(0, 6, 2) 'array{0, 2, 4, 6}' %}

https://twig.symfony.com/doc/3.x/functions/constant.html
{% assert_type constant('DATE_W3C') "'Y-m-d\\\\TH:i:sP'" %}
Expand Down
4 changes: 2 additions & 2 deletions tests/EndToEnd/Globals/globals.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% assert_type app "Symfony\\Bridge\\Twig\\AppVariable" %}
{% assert_type app 'Symfony\\Bridge\\Twig\\AppVariable' %}

{% block main %}
{% assert_type app "Symfony\\Bridge\\Twig\\AppVariable" %}
{% assert_type app 'Symfony\\Bridge\\Twig\\AppVariable' %}
{% endblock %}
4 changes: 2 additions & 2 deletions tests/EndToEnd/Globals/override.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% assert_type app "Symfony\\Bridge\\Twig\\AppVariable" %}
{% assert_type app 'Symfony\\Bridge\\Twig\\AppVariable' %}

{% set app = false %}

{% block main %}
{% assert_type app "false" %}
{% assert_type app 'false' %}
{% endblock %}
24 changes: 12 additions & 12 deletions tests/EndToEnd/Include/include_block.twig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{% set somethingInTheContext = true %}

{% include '@EndToEnd/Include/_footer.twig' %}
{% include '@EndToEnd/Include/_footer.twig' only %}
{% include '@EndToEnd/Include/_footer.twig' with { title: 'Hello, World!' } %}
{% include '@EndToEnd/Include/_footer.twig' with { title: 'Hello, World!' } only %}
{{ include('@EndToEnd/Include/_footer.twig') }}
{{ include('@EndToEnd/Include/_footer.twig', [], false) }}
{{ include('@EndToEnd/Include/_footer.twig', { title: 'Hello, World!' }) }}
{{ include('@EndToEnd/Include/_footer.twig', { title: 'Hello, World!' }, false) }}

{% include '@EndToEnd/Include/maybe-exists.twig' ignore missing %}
{% include '@EndToEnd/Include/maybe-exists.twig' ignore missing only %}
{% include '@EndToEnd/Include/maybe-exists.twig' ignore missing with { title: 'Hello, World!' } %}
{% include '@EndToEnd/Include/maybe-exists.twig' ignore missing with { title: 'Hello, World!' } only %}
{{ include('@EndToEnd/Include/maybe-exists.twig', [], true, true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', [], false, true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', { title: 'Hello, World!' }, true, true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', { title: 'Hello, World!' }, false, true) }}

{% include ['@EndToEnd/Include/maybe-exists.twig', '@EndToEnd/Include/_footer.twig'] %}
{% include ['@EndToEnd/Include/maybe-exists.twig', '@EndToEnd/Include/_footer.twig'] ignore missing %}
{{ include(['@EndToEnd/Include/maybe-exists.twig', '@EndToEnd/Include/_footer.twig']) }}
{{ include(['@EndToEnd/Include/maybe-exists.twig', '@EndToEnd/Include/_footer.twig'], [], true, true) }}

{% set template = '@EndToEnd/Include/_footer.twig' %}
{% include template %}
{{ include(template) }}

{% types {
isMobile: 'bool'
} %}

{% include isMobile ? '@EndToEnd/Include/isMobile.twig' : '@EndToEnd/Include/_footer.twig' %}
{{ include(isMobile ? '@EndToEnd/Include/isMobile.twig' : '@EndToEnd/Include/_footer.twig') }}
12 changes: 6 additions & 6 deletions tests/EndToEnd/Include/include_function.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% set somethingInTheContext = true %}

{{ include('@EndToEnd/Include/_footer.twig') }}
{{ include('@EndToEnd/Include/_footer.twig', with_context = false) }}
{{ include('@EndToEnd/Include/_footer.twig', with_context=false) }}
{{ include('@EndToEnd/Include/_footer.twig', { title: 'Hello, World!' }) }}
{{ include('@EndToEnd/Include/_footer.twig', { title: 'Hello, World!' }, with_context = false) }}
{{ include('@EndToEnd/Include/_footer.twig', { title: 'Hello, World!' }, with_context=false) }}

{{ include('@EndToEnd/Include/maybe-exists.twig', ignore_missing = true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', ignore_missing = true, with_context = false) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', { title: 'Hello, World!' }, ignore_missing = true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', { title: 'Hello, World!' }, with_context = false) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', ignore_missing=true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', ignore_missing=true, with_context=false) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', { title: 'Hello, World!' }, ignore_missing=true) }}
{{ include('@EndToEnd/Include/maybe-exists.twig', { title: 'Hello, World!' }, with_context=false) }}

{{ include(['@EndToEnd/Include/maybe-exists.twig', '@EndToEnd/Include/_footer.twig']) }}

Expand Down
2 changes: 1 addition & 1 deletion tests/EndToEnd/Inheritance/_layout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
</html>

{# {% macro hello(name) %} #}
{# HELLO {{ name }} #}
{# HELLO {{ name }} #}
{# {% endmacro %} #}
3 changes: 1 addition & 2 deletions tests/EndToEnd/Inheritance/case10.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "@EndToEnd/Inheritance/_layout.twig" %}
{% extends '@EndToEnd/Inheritance/_layout.twig' %}

{% block main %}
{% assert_variable_exists doesNotExist no %}
Expand All @@ -9,4 +9,3 @@

{{ parent() }}
{% endblock %}

4 changes: 2 additions & 2 deletions tests/EndToEnd/Inheritance/case4.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "@EndToEnd/Inheritance/_layout.twig" %}
{% import "@EndToEnd/Inheritance/_layout.twig" as layout %}
{% extends '@EndToEnd/Inheritance/_layout.twig' %}
{% import '@EndToEnd/Inheritance/_layout.twig' as layout %}

{% block main %}
<h1>{{ subtitle }}</h1>
Expand Down
4 changes: 2 additions & 2 deletions tests/EndToEnd/Inheritance/case5.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "@EndToEnd/Inheritance/_layout.twig" %}
{% import "@EndToEnd/Inheritance/_layout.twig" as layout %}
{% extends '@EndToEnd/Inheritance/_layout.twig' %}
{% import '@EndToEnd/Inheritance/_layout.twig' as layout %}

{% set title = 'Welcome' %}
{% set subtitle = 'Welcome' %}
Expand Down
6 changes: 3 additions & 3 deletions tests/EndToEnd/Inheritance/case6.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% use "@EndToEnd/Inheritance/_layout.twig" %}
{% use "@EndToEnd/Inheritance/_other.twig" with main as other_main %}
{% use '@EndToEnd/Inheritance/_layout.twig' %}
{% use '@EndToEnd/Inheritance/_other.twig' with main as other_main %}

{% set subtitle = 'Hello' %}
{% assert_type subtitle "'Hello'" %}
Expand All @@ -18,7 +18,7 @@
{% endblock %}

{% assert_type subtitle "'Hello'" %}
{% assert_type name "*ERROR*" %}
{% assert_type name '*ERROR*' %}

{% block footer %}
<footer>Copyright</footer>
Expand Down
5 changes: 2 additions & 3 deletions tests/EndToEnd/Inheritance/case7.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{% extends "@EndToEnd/Inheritance/_layout.twig" %}
{% import "@EndToEnd/Inheritance/_layout.twig" as layout %}
{% extends '@EndToEnd/Inheritance/_layout.twig' %}
{% import '@EndToEnd/Inheritance/_layout.twig' as layout %}

{% set title = 'Welcome' %}

{% block header %}
Override header
{% endblock %}

2 changes: 1 addition & 1 deletion tests/EndToEnd/Inheritance/case8.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "@EndToEnd/Inheritance/_layout.twig" %}
{% extends '@EndToEnd/Inheritance/_layout.twig' %}

{% set title = 'Welcome' %}
{% set subtitle = 'Welcome' %}
2 changes: 1 addition & 1 deletion tests/EndToEnd/Inheritance/case9.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set number = 1 %}

{% block main %}
{% assert_type number "1|3|5" %}
{% assert_type number '1|3|5' %}
{% endblock %}

{% set number = 3 %}
Expand Down
2 changes: 1 addition & 1 deletion tests/EndToEnd/Inheritance/dynamic_inheritance.twig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% set template = "@EndToEnd/Inheritance/_layout.twig" %}
{% set template = '@EndToEnd/Inheritance/_layout.twig' %}
{% extends template %}
2 changes: 1 addition & 1 deletion tests/EndToEnd/Macros/layout.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% import "@EndToEnd/Macros/macros.twig" as greeter %}
{% import '@EndToEnd/Macros/macros.twig' as greeter %}

{% macro copyright(year) %}
Copyright {{ year }}
Expand Down
4 changes: 2 additions & 2 deletions tests/EndToEnd/RenderPoints/form.html.twig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% assert_type form1 "Symfony\\Component\\Form\\FormView" %}
{% assert_type form2 "Symfony\\Component\\Form\\FormView" %}
{% assert_type form1 'Symfony\\Component\\Form\\FormView' %}
{% assert_type form2 'Symfony\\Component\\Form\\FormView' %}
1 change: 0 additions & 1 deletion tests/EndToEnd/Types/always_false.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
{% if not allowed %}
No access
{% endif %}

2 changes: 1 addition & 1 deletion tests/EndToEnd/Types/case3.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{% for name in names %}
Hello {{ name }}
{% assert_type name "string" %}
{% assert_type name 'string' %}
{% endfor %}

{% assert_type name "'Ruud'" %}
11 changes: 5 additions & 6 deletions tests/EndToEnd/Types/loop_inside_loop.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
dates: 'array<int, list<DateTime>>',
} %}

{% assert_type dates "array<int, list<DateTime>>" %}
{% assert_type dates 'array<int, list<DateTime>>' %}

{% for id, dateList in dates %}
{% assert_type id "int" %}
{% assert_type dateList "list<DateTime>" %}
{% assert_type id 'int' %}
{% assert_type dateList 'list<DateTime>' %}

{% for date in dateList %}
{% assert_type date "DateTime" %}
{% assert_type date 'DateTime' %}

{% set result = date.getOffset() %}
{% assert_type result "int" %}
{% assert_type result 'int' %}

<p>{{ date.getOffset() }}</p>
{% endfor %}
{% endfor %}

Loading

0 comments on commit 6a3415b

Please sign in to comment.