Skip to content

Commit 2e22ceb

Browse files
authored
Fixed issues related to twig/twig 3.15 in tests
1 parent 9fda0ec commit 2e22ceb

36 files changed

+719
-217
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12945,11 +12945,6 @@ parameters:
1294512945
count: 1
1294612946
path: src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php
1294712947

12948-
-
12949-
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Templating\\\\Twig\\\\Extension\\\\ContentExtension\\:\\:getFunctions\\(\\) return type has no value type specified in iterable type array\\.$#"
12950-
count: 1
12951-
path: src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php
12952-
1295312948
-
1295412949
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Templating\\\\Twig\\\\Extension\\\\ContentExtension\\:\\:getTranslatedField\\(\\) should return Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field but returns Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
1295512950
count: 1
@@ -12960,26 +12955,11 @@ parameters:
1296012955
count: 2
1296112956
path: src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php
1296212957

12963-
-
12964-
message: "#^Property Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Templating\\\\Twig\\\\Extension\\\\ContentExtension\\:\\:\\$logger \\(Psr\\\\Log\\\\LoggerInterface\\) does not accept Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
12965-
count: 1
12966-
path: src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php
12967-
1296812958
-
1296912959
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Templating\\\\Twig\\\\Extension\\\\CoreExtension\\:\\:getGlobals\\(\\) return type has no value type specified in iterable type array\\.$#"
1297012960
count: 1
1297112961
path: src/lib/MVC/Symfony/Templating/Twig/Extension/CoreExtension.php
1297212962

12973-
-
12974-
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Templating\\\\Twig\\\\Extension\\\\DataAttributesExtension\\:\\:getFilters\\(\\) return type has no value type specified in iterable type array\\.$#"
12975-
count: 1
12976-
path: src/lib/MVC/Symfony/Templating/Twig/Extension/DataAttributesExtension.php
12977-
12978-
-
12979-
message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Templating\\\\Twig\\\\Extension\\\\DataAttributesExtension\\:\\:serializeDataAttributes\\(\\) has parameter \\$dataAttributes with no value type specified in iterable type array\\.$#"
12980-
count: 1
12981-
path: src/lib/MVC/Symfony/Templating/Twig/Extension/DataAttributesExtension.php
12982-
1298312963
-
1298412964
message: "#^Parameter \\#1 \\$string of function htmlspecialchars expects string, string\\|false given\\.$#"
1298512965
count: 1

src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList;
1717
use Ibexa\Core\Helper\TranslationHelper;
1818
use Psr\Log\LoggerInterface;
19+
use Psr\Log\NullLogger;
1920
use Twig\Extension\AbstractExtension;
2021
use Twig\TwigFunction;
2122

@@ -25,6 +26,8 @@
2526
*/
2627
class ContentExtension extends AbstractExtension
2728
{
29+
use DeprecationOptionsTrait;
30+
2831
/** @var \Ibexa\Contracts\Core\Repository\Repository */
2932
protected $repository;
3033

@@ -50,24 +53,19 @@ public function __construct(
5053
$this->translationHelper = $translationHelper;
5154
$this->fieldHelper = $fieldHelper;
5255
$this->fieldsGroupsList = $fieldsGroupsList;
53-
$this->logger = $logger;
56+
$this->logger = $logger ?? new NullLogger();
5457
}
5558

5659
/**
5760
* Returns a list of functions to add to the existing list.
58-
*
59-
* @return array
6061
*/
61-
public function getFunctions()
62+
public function getFunctions(): array
6263
{
6364
return [
6465
new TwigFunction(
6566
'ez_content_name',
6667
[$this, 'getTranslatedContentName'],
67-
[
68-
'deprecated' => '4.0',
69-
'alternative' => 'ibexa_content_name',
70-
]
68+
$this->getDeprecationOptions('ibexa_content_name'),
7169
),
7270
new TwigFunction(
7371
'ibexa_content_name',
@@ -76,10 +74,7 @@ public function getFunctions()
7674
new TwigFunction(
7775
'ez_field_value',
7876
[$this, 'getTranslatedFieldValue'],
79-
[
80-
'deprecated' => '4.0',
81-
'alternative' => 'ibexa_field_value',
82-
]
77+
$this->getDeprecationOptions('ibexa_field_value'),
8378
),
8479
new TwigFunction(
8580
'ibexa_field_value',
@@ -88,10 +83,7 @@ public function getFunctions()
8883
new TwigFunction(
8984
'ez_field',
9085
[$this, 'getTranslatedField'],
91-
[
92-
'deprecated' => '4.0',
93-
'alternative' => 'ibexa_field',
94-
]
86+
$this->getDeprecationOptions('ibexa_field'),
9587
),
9688
new TwigFunction(
9789
'ibexa_field',
@@ -100,10 +92,7 @@ public function getFunctions()
10092
new TwigFunction(
10193
'ez_field_is_empty',
10294
[$this, 'isFieldEmpty'],
103-
[
104-
'deprecated' => '4.0',
105-
'alternative' => 'ibexa_field_is_empty',
106-
]
95+
$this->getDeprecationOptions('ibexa_field_is_empty'),
10796
),
10897
new TwigFunction(
10998
'ibexa_has_field',
@@ -116,10 +105,7 @@ public function getFunctions()
116105
new TwigFunction(
117106
'ez_field_name',
118107
[$this, 'getTranslatedFieldDefinitionName'],
119-
[
120-
'deprecated' => '4.0',
121-
'alternative' => 'ibexa_field_name',
122-
]
108+
$this->getDeprecationOptions('ibexa_field_name'),
123109
),
124110
new TwigFunction(
125111
'ibexa_field_name',
@@ -128,10 +114,7 @@ public function getFunctions()
128114
new TwigFunction(
129115
'ez_field_description',
130116
[$this, 'getTranslatedFieldDefinitionDescription'],
131-
[
132-
'deprecated' => '4.0',
133-
'alternative' => 'ibexa_field_description',
134-
]
117+
$this->getDeprecationOptions('ibexa_field_description'),
135118
),
136119
new TwigFunction(
137120
'ibexa_field_description',
@@ -144,10 +127,7 @@ public function getFunctions()
144127
new TwigFunction(
145128
'ez_content_field_identifier_first_filled_image',
146129
[$this, 'getFirstFilledImageFieldIdentifier'],
147-
[
148-
'deprecated' => '4.0',
149-
'alternative' => 'ibexa_content_field_identifier_first_filled_image',
150-
]
130+
$this->getDeprecationOptions('ibexa_content_field_identifier_first_filled_image'),
151131
),
152132
new TwigFunction(
153133
'ibexa_content_field_identifier_first_filled_image',

src/lib/MVC/Symfony/Templating/Twig/Extension/DataAttributesExtension.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@
1616
*/
1717
class DataAttributesExtension extends AbstractExtension
1818
{
19+
use DeprecationOptionsTrait;
20+
1921
/**
2022
* Returns a list of functions to add to the existing list.
21-
*
22-
* @return array
2323
*/
2424
public function getFilters(): array
2525
{
2626
return [
2727
new TwigFilter(
2828
'ez_data_attributes_serialize',
2929
[$this, 'serializeDataAttributes'],
30-
[
31-
'is_safe' => ['html'],
32-
'deprecated' => '4.0',
33-
'alternative' => 'ibexa_data_attributes_serialize',
34-
]
30+
array_merge(
31+
[
32+
'is_safe' => ['html'],
33+
],
34+
$this->getDeprecationOptions('ibexa_data_attributes_serialize'),
35+
),
3536
),
3637
new TwigFilter(
3738
'ibexa_data_attributes_serialize',
@@ -45,7 +46,7 @@ public function getFilters(): array
4546
* Processes an associative list of data attributes and returns them as HTML attributes list
4647
* in the form of <code>data-<attribute_name>="<attribute_value>"</code>.
4748
*
48-
* @param array $dataAttributes
49+
* @param array<string, mixed> $dataAttributes
4950
*
5051
* @return string
5152
*/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Core\MVC\Symfony\Templating\Twig\Extension;
10+
11+
use Twig\DeprecatedCallableInfo;
12+
13+
/**
14+
* This trait provides ability to deprecate Twig functions, maintaining compatibility with twig/twig prior to 3.15.
15+
*
16+
* @internal
17+
*/
18+
trait DeprecationOptionsTrait
19+
{
20+
/**
21+
* @phpstan-param non-empty-string $newFunction
22+
*
23+
* @phpstan-return array{
24+
* deprecation_info: object,
25+
* }|array{
26+
* deprecated: non-empty-string,
27+
* deprecating_package: non-empty-string,
28+
* alternative: non-empty-string,
29+
* }
30+
*/
31+
private function getDeprecationOptions(string $newFunction): array
32+
{
33+
if (class_exists(DeprecatedCallableInfo::class)) {
34+
return [
35+
'deprecation_info' => new DeprecatedCallableInfo('ibexa/core', '4.0', $newFunction),
36+
];
37+
}
38+
39+
// Compatibility with twig/twig prior to 3.15
40+
return [
41+
'deprecated' => '4.0',
42+
'deprecating_package' => 'ibexa/core',
43+
'alternative' => $newFunction,
44+
];
45+
}
46+
}

src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class FieldRenderingExtension extends AbstractExtension
2424
{
25+
use DeprecationOptionsTrait;
26+
2527
/** @var \Ibexa\Core\MVC\Symfony\Templating\FieldBlockRendererInterface */
2628
private $fieldBlockRenderer;
2729

@@ -66,12 +68,13 @@ public function getFunctions()
6668
new TwigFunction(
6769
'ez_render_field',
6870
$renderFieldCallable,
69-
[
70-
'is_safe' => ['html'],
71-
'needs_environment' => true,
72-
'deprecated' => '4.0',
73-
'alternative' => 'ibexa_render_field',
74-
]
71+
array_merge(
72+
[
73+
'is_safe' => ['html'],
74+
'needs_environment' => true,
75+
],
76+
$this->getDeprecationOptions('ibexa_render_field'),
77+
),
7578
),
7679
new TwigFunction(
7780
'ibexa_render_field',
@@ -81,12 +84,13 @@ public function getFunctions()
8184
new TwigFunction(
8285
'ez_render_field_definition_settings',
8386
$renderFieldDefinitionSettingsCallable,
84-
[
85-
'is_safe' => ['html'],
86-
'needs_environment' => true,
87-
'deprecated' => '4.0',
88-
'alternative' => 'ibexa_render_field_definition_settings',
89-
]
87+
array_merge(
88+
[
89+
'is_safe' => ['html'],
90+
'needs_environment' => true,
91+
],
92+
$this->getDeprecationOptions('ibexa_render_field_definition_settings'),
93+
),
9094
),
9195
new TwigFunction(
9296
'ibexa_render_field_definition_settings',

src/lib/MVC/Symfony/Templating/Twig/Extension/FileSizeExtension.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class FileSizeExtension extends AbstractExtension
2222
{
23+
use DeprecationOptionsTrait;
24+
2325
/**
2426
* @param \Symfony\Contracts\Translation\TranslatorInterface $translator
2527
*/
@@ -77,10 +79,7 @@ public function getFilters()
7779
new TwigFilter(
7880
'ez_file_size',
7981
[$this, 'sizeFilter'],
80-
[
81-
'deprecated' => '4.0',
82-
'alternative' => 'ibexa_file_size',
83-
]
82+
$this->getDeprecationOptions('ibexa_file_size'),
8483
),
8584
new TwigFilter(
8685
'ibexa_file_size',

src/lib/MVC/Symfony/Templating/Twig/Extension/ImageExtension.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
class ImageExtension extends AbstractExtension
2020
{
21+
use DeprecationOptionsTrait;
22+
2123
/** @var \Ibexa\Contracts\Core\Variation\VariationHandler */
2224
private $imageVariationService;
2325

@@ -30,17 +32,18 @@ public function __construct(VariationHandler $imageVariationService, AssetMapper
3032
$this->assetMapper = $assetMapper;
3133
}
3234

33-
public function getFunctions()
35+
public function getFunctions(): array
3436
{
3537
return [
3638
new TwigFunction(
3739
'ez_image_alias',
3840
[$this, 'getImageVariation'],
39-
[
40-
'is_safe' => ['html'],
41-
'deprecated' => '4.0',
42-
'alternative' => 'ibexa_image_alias',
43-
]
41+
array_merge(
42+
[
43+
'is_safe' => ['html'],
44+
],
45+
$this->getDeprecationOptions('ibexa_image_alias'),
46+
),
4447
),
4548
new TwigFunction(
4649
'ibexa_image_alias',
@@ -50,11 +53,12 @@ public function getFunctions()
5053
new TwigFunction(
5154
'ez_content_field_identifier_image_asset',
5255
[$this, 'getImageAssetContentFieldIdentifier'],
53-
[
54-
'is_safe' => ['html'],
55-
'deprecated' => '4.0',
56-
'alternative' => 'ibexa_content_field_identifier_image_asset',
57-
]
56+
array_merge(
57+
[
58+
'is_safe' => ['html'],
59+
],
60+
$this->getDeprecationOptions('ibexa_content_field_identifier_image_asset'),
61+
),
5862
),
5963
new TwigFunction(
6064
'ibexa_content_field_identifier_image_asset',

0 commit comments

Comments
 (0)