Skip to content

Commit 255a9f6

Browse files
authored
Fix return type and implement getCatalogues() (#470)
* Fix return type and implement getCatalogues() * Typecast the result of trans() to string * Fix code styles * Fix static PHPStan * Fix code styles one more time * Fix wrong property name - my bad
1 parent ea84216 commit 255a9f6

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Tests/Unit/Translator/EditInPlaceTranslatorTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ public function testDisabled(): void
6969
$activator = new FakeActivator(false);
7070
$service = new EditInPlaceTranslator($symfonyTranslator, $activator, $requestStack);
7171

72-
$this->assertNull(
73-
$service->trans('key', [])
74-
);
72+
$this->assertEmpty($service->trans('key', []));
7573
}
7674

7775
public function testHtmlTranslation(): void

Translator/EditInPlaceTranslator.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,34 @@ public function __construct($translator, ActivatorInterface $activator, RequestS
6363
}
6464

6565
/**
66-
* @see Translator::getCatalogue
66+
* @see Translator::getCatalogue()
6767
*/
6868
public function getCatalogue($locale = null): MessageCatalogueInterface
6969
{
7070
return $this->translator->getCatalogue($locale);
7171
}
7272

73+
/**
74+
* @see Translator::getCatalogues()
75+
*/
76+
public function getCatalogues(): array
77+
{
78+
if (!\method_exists($this->translator, 'getCatalogues')) {
79+
throw new \Exception(\sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__));
80+
}
81+
82+
return $this->translator->getCatalogues();
83+
}
84+
7385
/**
7486
* @see Translator::trans
7587
*/
76-
public function trans($id, array $parameters = [], $domain = null, $locale = null): ?string
88+
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
7789
{
7890
$original = $this->translator->trans($id, $parameters, $domain, $locale);
7991
$request = LegacyHelper::getMainRequest($this->requestStack);
8092
if (!$this->activator->checkRequest($request)) {
81-
return $original;
93+
return (string) $original;
8294
}
8395

8496
$plain = $this->translator->trans($id, [], $domain, $locale);

Translator/FallbackTranslator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ public function getCatalogue($locale = null): MessageCatalogueInterface
137137
return $this->symfonyTranslator->getCatalogue($locale);
138138
}
139139

140+
public function getCatalogues(): array
141+
{
142+
if (!\method_exists($this->symfonyTranslator, 'getCatalogues')) {
143+
throw new \Exception(\sprintf('%s method is not available! Please, upgrade to Symfony 6 in order to to use it', __METHOD__));
144+
}
145+
146+
return $this->symfonyTranslator->getCatalogues();
147+
}
148+
140149
/**
141150
* Passes through all unknown calls onto the translator object.
142151
*/

0 commit comments

Comments
 (0)