Completed
Push — development ( 1cc14b...5a65d0 )
by Thomas
18:18 queued 34s
created

src/OcLegacy/Translation/TranslationService.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace OcLegacy\Translation;
4
5
use Symfony\Component\Translation\Loader\YamlFileLoader;
6
use Symfony\Component\Translation\MessageSelector;
7
use Symfony\Component\Translation\Translator;
8
use Symfony\Component\Translation\TranslatorInterface;
9
10
class TranslationService implements TranslatorInterface
11
{
12
    private $translator;
13
14
    public function __construct()
15
    {
16
        $translator = new Translator('de', new MessageSelector());
0 ignored issues
show
new \Symfony\Component\T...ation\MessageSelector() is of type object<Symfony\Component...lation\MessageSelector>, but the function expects a object<Symfony\Component...ormatterInterface>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
        $translator->setFallbackLocales(['en']);
18
19
        $yamlLoader = new YamlFileLoader();
20
        $translator->addLoader('yml', $yamlLoader);
21
22
        foreach (['de', 'fr', 'nl', 'es', 'pl', 'it', 'ru'] as $languageKey) {
23
            $translator->addResource('yml', __DIR__ . '/../../../app/Resources/translations/constants.' . $languageKey . '.yml', $languageKey);
24
            $translator->addResource('yml', __DIR__ . '/../../../app/Resources/translations/messages.' . $languageKey . '.yml', $languageKey);
25
            $translator->addResource('yml', __DIR__ . '/../../../app/Resources/translations/validators.' . $languageKey . '.yml', $languageKey);
26
        }
27
28
        $this->translator = $translator;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function trans($id, array $parameters = [], $domain = null, $locale = null)
35
    {
36
        return $this->translator->trans($id, $parameters, $domain, $locale);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
43
    {
44
        return $this->translator->transChoice($id, $number, $parameters, $domain, $locale);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function setLocale($locale)
51
    {
52
        return $this->translator->setLocale($locale);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getLocale()
59
    {
60
        return $this->translator->getLocale();
61
    }
62
}
63