Skip to content

Commit 17b0018

Browse files
committed
Apply rectors:
- PushRequestToRequestStackConstructorRector - GetFunctionsToAsTwigFunctionAttributeRector - GetFiltersToAsTwigFilterAttributeRector
1 parent 611678c commit 17b0018

15 files changed

Lines changed: 67 additions & 171 deletions

File tree

config/packages/test/config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ services:
66

77
engineblock.twig.extension.global_site_notice:
88
class: OpenConext\EngineBlockBundle\Twig\Extensions\Extension\FunctionalTestingGlobalSiteNotice
9+
autoconfigure: true
910
arguments:
1011
- "@request_stack"
1112
- "%global.site_notice.allowed.tags%"
12-
tags:
13-
- { name: 'twig.extension' }
1413

1514
web_profiler:
1615
toolbar: false

config/services/ci/services.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ services:
132132
- '%stepup.sfo.override_engine_entityid%'
133133

134134
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\FunctionalTestingGlobalSiteNotice:
135+
autoconfigure: true
135136
arguments:
136137
- "@request_stack"
137138
- "%global.site_notice.allowed.tags%"
138-
tags:
139-
- { name: 'twig.extension' }

config/services/services.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ services:
2424
- { name: openconext.monitor.health_check }
2525

2626
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\Spaceless:
27-
tags:
28-
- { name: 'twig.extension' }
27+
autoconfigure: true
2928

3029
OpenConext\EngineBlockBundle\Value\ExecutionTime:
3130
factory: [ OpenConext\EngineBlockBundle\Value\ExecutionTime, 'of' ]
@@ -296,53 +295,46 @@ services:
296295
- '@OpenConext\EngineBlock\Metadata\MetadataRepository\CachedDoctrineMetadataRepository'
297296

298297
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\Debug:
299-
tags:
300-
- { name: 'twig.extension' }
298+
autoconfigure: true
301299

302300
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\Feedback:
301+
autoconfigure: true
303302
arguments:
304303
- '@engineblock.compat.application'
305304
- '@OpenConext\EngineBlockBundle\Configuration\ErrorFeedbackConfiguration'
306305
- '@engineblock.compat.repository.metadata'
307306
- '@OpenConext\EngineBlockBundle\Authentication\Service\SamlResponseHelper'
308-
tags:
309-
- { name: 'twig.extension' }
310307

311308
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\GlobalSiteNotice:
309+
autoconfigure: true
312310
arguments:
313311
- '%global.site_notice.show%'
314312
- '%global.site_notice.allowed.tags%'
315313
- '@translator'
316-
tags:
317-
- { name: 'twig.extension' }
318314

319315
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\I18n:
316+
autoconfigure: true
320317
arguments:
321318
- '@translator'
322-
tags:
323-
- { name: 'twig.extension' }
324319

325320
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\Locale:
321+
autoconfigure: true
326322
arguments:
327323
- '@request_stack'
328324
- '@OpenConext\EngineBlockBundle\Localization\LanguageSupportProvider'
329325
- '%locale%'
330-
tags:
331-
- { name: 'twig.extension' }
332326

333327
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\Metadata:
328+
autoconfigure: true
334329
arguments:
335330
- '@engineblock.compat.metadata.definitions'
336331
- '@translator'
337-
tags:
338-
- { name: 'twig.extension' }
339332

340333
OpenConext\EngineBlockBundle\Twig\Extensions\Extension\Wayf:
334+
autoconfigure: true
341335
arguments:
342336
- '@request_stack'
343337
- '@translator'
344-
tags:
345-
- { name: 'twig.extension' }
346338

347339
OpenConext\EngineBlockBundle\Service\DiscoverySelectionService:
348340

src/OpenConext/EngineBlockBundle/Twig/Extensions/Extension/Debug.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,19 @@
1818

1919
namespace OpenConext\EngineBlockBundle\Twig\Extensions\Extension;
2020

21-
use Twig\Extension\AbstractExtension;
22-
use Twig\TwigFunction;
21+
use Twig\Attribute\AsTwigFunction;
2322

2423
/**
2524
* The debug extension is used to provide var_dump, var_export and print_r functions for usage in Twig templates.
2625
*/
27-
class Debug extends AbstractExtension
26+
class Debug
2827
{
29-
public function getFunctions(): array
30-
{
31-
return [
32-
new TwigFunction('var_export', $this->varExport(...)),
33-
new TwigFunction('print_r', $this->printHumanReadable(...)),
34-
];
35-
}
36-
3728
/**
3829
* Provide var export functionality for use in Twig templates
3930
* @param mixed $expression
4031
* @return string
4132
*/
33+
#[AsTwigFunction(name: 'var_export')]
4234
public function varExport($expression)
4335
{
4436
return var_export($expression, true);
@@ -49,6 +41,7 @@ public function varExport($expression)
4941
* @param mixed $expression
5042
* @return string
5143
*/
44+
#[AsTwigFunction(name: 'print_r')]
5245
public function printHumanReadable($expression)
5346
{
5447
return print_r($expression, true);

src/OpenConext/EngineBlockBundle/Twig/Extensions/Extension/Feedback.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
use OpenConext\EngineBlockBundle\Value\FeedbackInformation;
2727
use OpenConext\EngineBlockBundle\Value\FeedbackInformationMap;
2828
use SAML2\XML\saml\Issuer;
29-
use Twig\Extension\AbstractExtension;
30-
use Twig\TwigFunction;
29+
use Twig\Attribute\AsTwigFunction;
3130

32-
class Feedback extends AbstractExtension
31+
class Feedback
3332
{
3433
/**
3534
* @var EngineBlock_ApplicationSingleton
@@ -63,23 +62,7 @@ public function __construct(
6362
$this->samlResponseHelper = $samlResponseHelper;
6463
}
6564

66-
public function getFunctions(): array
67-
{
68-
return [
69-
new TwigFunction('feedbackInfo', $this->getFeedbackInfo(...)),
70-
new TwigFunction('flushLog', $this->flushLog(...)),
71-
new TwigFunction('hasBackToSpLink', $this->hasBackToSpLink(...)),
72-
new TwigFunction('hasWikiLink', $this->hasWikiLink(...)),
73-
new TwigFunction('getWikiLink', $this->getWikiLink(...)),
74-
new TwigFunction('hasIdPContactMailLink', $this->hasIdPContactMailLink(...)),
75-
new TwigFunction('getIdPContactMailLink', $this->getIdPContactMailLink(...)),
76-
new TwigFunction('getIdpContactShortLabel', $this->getIdpContactShortLabel(...)),
77-
new TwigFunction('getSpName', $this->getSpName(...)),
78-
new TwigFunction('getAcu', $this->getAcu(...)),
79-
new TwigFunction('getSamlFailedResponse', $this->getSamlFailedResponse(...)),
80-
];
81-
}
82-
65+
#[AsTwigFunction(name: 'flushLog')]
8366
public function flushLog($message)
8467
{
8568
// For now use the EngineBlock_ApplicationSingleton to flush the log
@@ -89,6 +72,7 @@ public function flushLog($message)
8972
/**
9073
* @return FeedbackInformationMap
9174
*/
75+
#[AsTwigFunction(name: 'feedbackInfo')]
9276
public function getFeedbackInfo()
9377
{
9478
return $this->retrieveFeedbackInfo();
@@ -98,6 +82,7 @@ public function getFeedbackInfo()
9882
* @param string $templateName
9983
* @return bool
10084
*/
85+
#[AsTwigFunction(name: 'hasWikiLink')]
10186
public function hasWikiLink($templateName)
10287
{
10388
return $this->errorFeedbackConfiguration->hasWikiLink($templateName);
@@ -107,6 +92,7 @@ public function hasWikiLink($templateName)
10792
* @param string $templateName
10893
* @return string
10994
*/
95+
#[AsTwigFunction(name: 'getWikiLink')]
11096
public function getWikiLink($templateName)
11197
{
11298
return $this->errorFeedbackConfiguration->getWikiLink($templateName);
@@ -116,6 +102,7 @@ public function getWikiLink($templateName)
116102
* @param string $templateName
117103
* @return bool
118104
*/
105+
#[AsTwigFunction(name: 'hasIdPContactMailLink')]
119106
public function hasIdPContactMailLink($templateName)
120107
{
121108
return $this->errorFeedbackConfiguration->isIdPContactPage($templateName) && $this->getIdPContactMailLink();
@@ -125,6 +112,7 @@ public function hasIdPContactMailLink($templateName)
125112
* @param string $templateName
126113
* @return string
127114
*/
115+
#[AsTwigFunction(name: 'getIdpContactShortLabel')]
128116
public function getIdpContactShortLabel($templateName)
129117
{
130118
return $this->errorFeedbackConfiguration->getIdpContactShortLabel($templateName);
@@ -133,6 +121,7 @@ public function getIdpContactShortLabel($templateName)
133121
/**
134122
* @return string
135123
*/
124+
#[AsTwigFunction(name: 'getIdPContactMailLink')]
136125
public function getIdPContactMailLink()
137126
{
138127
$feedbackInfo = $this->retrieveFeedbackInfo();
@@ -153,6 +142,7 @@ public function getIdPContactMailLink()
153142
return '';
154143
}
155144

145+
#[AsTwigFunction(name: 'hasBackToSpLink')]
156146
public function hasBackToSpLink(): bool
157147
{
158148
$info = $this->retrieveFeedbackInfo();
@@ -165,17 +155,20 @@ public function hasBackToSpLink(): bool
165155
return $response !== '';
166156
}
167157

158+
#[AsTwigFunction(name: 'getSpName')]
168159
public function getSpName(): ?string
169160
{
170161
return $this->getFeedbackInfo()->get('serviceProviderName') ?? $this->getFeedbackInfo()->get('serviceProvider');
171162
}
172163

164+
#[AsTwigFunction(name: 'getAcu')]
173165
public function getAcu(): string
174166
{
175167
$info = $this->retrieveFeedbackInfo();
176168
return $this->samlResponseHelper->getAcu($info->get('serviceProvider'));
177169
}
178170

171+
#[AsTwigFunction(name: 'getSamlFailedResponse')]
179172
public function getSamlFailedResponse(): string
180173
{
181174
$session = $this->application->getSession();

src/OpenConext/EngineBlockBundle/Twig/Extensions/Extension/FunctionalTestingGlobalSiteNotice.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
namespace OpenConext\EngineBlockBundle\Twig\Extensions\Extension;
2020

2121
use Symfony\Component\HttpFoundation\RequestStack;
22-
use Twig\Extension\AbstractExtension;
23-
use Twig\TwigFunction;
22+
use Twig\Attribute\AsTwigFunction;
2423

25-
class FunctionalTestingGlobalSiteNotice extends AbstractExtension implements GlobalSiteNoticeInterface
24+
class FunctionalTestingGlobalSiteNotice implements GlobalSiteNoticeInterface
2625
{
2726
private $request;
2827

@@ -39,20 +38,13 @@ public function __construct(
3938
$this->allowedHtml = $allowedHtml;
4039
}
4140

42-
public function getFunctions(): array
43-
{
44-
return [
45-
new TwigFunction('shouldDisplayGlobalSiteNotice', $this->shouldDisplayGlobalSiteNotice(...)),
46-
new TwigFunction('getGlobalSiteNotice', $this->getGlobalSiteNotice(...)),
47-
new TwigFunction('getAllowedHtmlForNotice', $this->getAllowedHtmlForNotice(...)),
48-
];
49-
}
50-
41+
#[AsTwigFunction(name: 'shouldDisplayGlobalSiteNotice')]
5142
public function shouldDisplayGlobalSiteNotice() : bool
5243
{
5344
return (bool) $this->request->get('showGlobalSiteNotice', false);
5445
}
5546

47+
#[AsTwigFunction(name: 'getGlobalSiteNotice')]
5648
public function getGlobalSiteNotice(): string
5749
{
5850
$message = <<<MSG
@@ -73,6 +65,7 @@ public function getGlobalSiteNotice(): string
7365
return (string) $this->request->get('globalSiteNotice', $message);
7466
}
7567

68+
#[AsTwigFunction(name: 'getAllowedHtmlForNotice')]
7669
public function getAllowedHtmlForNotice(): string
7770
{
7871
return $this->allowedHtml;

src/OpenConext/EngineBlockBundle/Twig/Extensions/Extension/GlobalSiteNotice.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
namespace OpenConext\EngineBlockBundle\Twig\Extensions\Extension;
2020

2121
use Symfony\Contracts\Translation\TranslatorInterface;
22-
use Twig\Extension\AbstractExtension;
23-
use Twig\TwigFunction;
22+
use Twig\Attribute\AsTwigFunction;
2423

25-
class GlobalSiteNotice extends AbstractExtension
24+
class GlobalSiteNotice
2625
{
2726
/**
2827
* @var bool
@@ -49,25 +48,19 @@ public function __construct(
4948
$this->translator = $translator;
5049
}
5150

52-
public function getFunctions(): array
53-
{
54-
return [
55-
new TwigFunction('shouldDisplayGlobalSiteNotice', $this->shouldDisplayGlobalSiteNotice(...)),
56-
new TwigFunction('getGlobalSiteNotice', $this->getGlobalSiteNotice(...)),
57-
new TwigFunction('getAllowedHtmlForNotice', $this->getAllowedHtmlForNotice(...)),
58-
];
59-
}
60-
51+
#[AsTwigFunction(name: 'shouldDisplayGlobalSiteNotice')]
6152
public function shouldDisplayGlobalSiteNotice() : bool
6253
{
6354
return $this->shouldDisplayGlobalSiteNotice;
6455
}
6556

57+
#[AsTwigFunction(name: 'getGlobalSiteNotice')]
6658
public function getGlobalSiteNotice(): string
6759
{
6860
return $this->translator->trans('site_notice');
6961
}
7062

63+
#[AsTwigFunction(name: 'getAllowedHtmlForNotice')]
7164
public function getAllowedHtmlForNotice(): string
7265
{
7366
return $this->allowedHtml;

src/OpenConext/EngineBlockBundle/Twig/Extensions/Extension/I18n.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
namespace OpenConext\EngineBlockBundle\Twig\Extensions\Extension;
2020

2121
use Symfony\Contracts\Translation\TranslatorInterface;
22-
use Twig\Extension\AbstractExtension;
23-
use Twig\TwigFilter;
22+
use Twig\Attribute\AsTwigFilter;
2423

25-
class I18n extends AbstractExtension
24+
class I18n
2625
{
2726
/**
2827
* @var TranslatorInterface
@@ -34,20 +33,14 @@ public function __construct(TranslatorInterface $translator)
3433
$this->translator = $translator;
3534
}
3635

37-
public function getFilters()
38-
{
39-
return [
40-
new TwigFilter('trans', $this->translateSingular(...)),
41-
new TwigFilter('transchoice', $this->translatePlural(...)),
42-
];
43-
}
44-
36+
#[AsTwigFilter(name: 'trans')]
4537
public function translateSingular($id, array $parameters = [], $domain = null, $locale = null)
4638
{
4739
$parameters = $this->addDefaultPlaceholders($parameters);
4840
return $this->translator->trans($id, $parameters, $domain, $locale);
4941
}
5042

43+
#[AsTwigFilter(name: 'transchoice')]
5144
public function translatePlural($id, $count, array $parameters = [], $domain = null, $locale = null)
5245
{
5346
$parameters = $this->addDefaultPlaceholders($parameters);

0 commit comments

Comments
 (0)