for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SaasReady\Services;
use SaasReady\Contracts\TranslationRepositoryContract;
class Translator
{
public function __construct(private TranslationRepositoryContract $translationRepository)
}
public function translate(string $key, array $variables = []): string
$translatedText = $this->translationRepository->getTranslation($key);
$replacements = collect($variables)->mapWithKeys(fn ($value, $placeholder) => [
collect
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
$replacements = /** @scrutinizer ignore-call */ collect($variables)->mapWithKeys(fn ($value, $placeholder) => [
'{' . trim($placeholder, '{}') . '}' => $value,
])->toArray();
return strtr($translatedText, $replacements);