Skip to content

Commit

Permalink
Add missing type hints to translation classes (see #5838)
Browse files Browse the repository at this point in the history
Description
-----------

This should make the CI green again for Contao 5.2

Should we backport this to 5.1? I think we can because all those types are forced by the interfaces anyways.

Commits
-------

c7437cd Add missing type hints to translation classes
  • Loading branch information
ausi committed Mar 6, 2023
1 parent e5ce627 commit ec90535
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions core-bundle/src/Translation/DataCollectorTranslator.php
Expand Up @@ -40,7 +40,7 @@ public function __construct(TranslatorInterface $translator)
* Gets the translation from Contao’s $GLOBALS['TL_LANG'] array if the message
* domain starts with "contao_". The locale parameter is ignored in this case.
*/
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
public function trans(string|null $id, array $parameters = [], string $domain = null, string $locale = null): string
{
$translated = $this->translator->trans($id, $parameters, $domain, $locale);

Expand All @@ -54,7 +54,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
return $translated;
}

public function setLocale($locale): void
public function setLocale(string $locale): void
{
$this->translator->setLocale($locale);
}
Expand All @@ -64,7 +64,7 @@ public function getLocale(): string
return $this->translator->getLocale();
}

public function getCatalogue($locale = null): MessageCatalogueInterface
public function getCatalogue(string $locale = null): MessageCatalogueInterface
{
return $this->translator->getCatalogue($locale);
}
Expand Down
12 changes: 6 additions & 6 deletions core-bundle/src/Translation/MessageCatalogue.php
Expand Up @@ -57,7 +57,7 @@ public function all(string $domain = null): array
return $this->parent->all($domain);
}

public function set($id, $translation, $domain = 'messages'): void
public function set(string $id, string $translation, string $domain = 'messages'): void
{
if ($this->isContaoDomain($domain)) {
throw new LogicException(sprintf('Setting Contao translations via %s() is not yet supported', __METHOD__));
Expand All @@ -66,7 +66,7 @@ public function set($id, $translation, $domain = 'messages'): void
$this->parent->set($id, $translation, $domain);
}

public function has($id, $domain = 'messages'): bool
public function has(string $id, string $domain = 'messages'): bool
{
if (!$this->isContaoDomain($domain)) {
return $this->parent->has($id, $domain);
Expand All @@ -75,7 +75,7 @@ public function has($id, $domain = 'messages'): bool
return null !== $this->loadMessage($id, $domain);
}

public function defines($id, $domain = 'messages'): bool
public function defines(string $id, string $domain = 'messages'): bool
{
if (!$this->isContaoDomain($domain)) {
return $this->parent->defines($id, $domain);
Expand All @@ -84,7 +84,7 @@ public function defines($id, $domain = 'messages'): bool
return null !== $this->loadMessage($id, $domain);
}

public function get($id, $domain = 'messages'): string
public function get(string $id, string $domain = 'messages'): string
{
if (!$this->isContaoDomain($domain)) {
return $this->parent->get($id, $domain);
Expand All @@ -93,7 +93,7 @@ public function get($id, $domain = 'messages'): string
return $this->loadMessage($id, $domain) ?? $id;
}

public function replace($messages, $domain = 'messages'): void
public function replace(array $messages, string $domain = 'messages'): void
{
if ($this->isContaoDomain($domain)) {
throw new LogicException(sprintf('Setting Contao translations via %s() is not yet supported', __METHOD__));
Expand All @@ -102,7 +102,7 @@ public function replace($messages, $domain = 'messages'): void
$this->parent->replace($messages, $domain);
}

public function add($messages, $domain = 'messages'): void
public function add(array $messages, string $domain = 'messages'): void
{
if ($this->isContaoDomain($domain)) {
throw new LogicException(sprintf('Setting Contao translations via %s() is not yet supported', __METHOD__));
Expand Down
6 changes: 3 additions & 3 deletions core-bundle/src/Translation/Translator.php
Expand Up @@ -44,7 +44,7 @@ public function __construct(
* Gets the translation from Contao’s $GLOBALS['TL_LANG'] array if the message
* domain starts with "contao_".
*/
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string
{
// Forward to the default translator
if (null === $domain || !str_starts_with($domain, 'contao_')) {
Expand All @@ -66,7 +66,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
return $translated;
}

public function setLocale($locale): void
public function setLocale(string $locale): void
{
$this->translator->setLocale($locale);
}
Expand All @@ -76,7 +76,7 @@ public function getLocale(): string
return $this->translator->getLocale();
}

public function getCatalogue($locale = null): MessageCatalogue
public function getCatalogue(string $locale = null): MessageCatalogue
{
$parentCatalog = $this->translator->getCatalogue($locale);

Expand Down

0 comments on commit ec90535

Please sign in to comment.