Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing type hints to translation classes #5838

Merged
merged 1 commit into from Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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