Issues (2884)

src/App/I18n/Translator.php (1 issue)

1
<?php
2
3
namespace Jaxon\App\I18n;
4
5
/**
6
 * Translator.php
7
 *
8
 * A translator coupled with a config event listener.
9
 *
10
 * @package jaxon-core
11
 * @author Thierry Feuzeu <[email protected]>
12
 * @copyright 2022 Thierry Feuzeu <[email protected]>
13
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
14
 * @link https://github.com/jaxon-php/jaxon-core
15
 */
16
17
use Jaxon\App\Config\ConfigListenerInterface;
18
use Jaxon\Utils\Config\Config;
19
use Jaxon\Utils\Translation\Translator as BaseTranslator;
20
21
class Translator extends BaseTranslator implements ConfigListenerInterface
22
{
23
    /**
24
     * @inheritDoc
25
     */
26
    public function onChange(Config $xConfig, string $sName)
27
    {
28
        // Set the library language any time the config is changed.
29
        if($sName === '' || $sName === 'core.language')
30
        {
31
            $this->setLocale($xConfig->getOption('core.language'));
0 ignored issues
show
It seems like $xConfig->getOption('core.language') can also be of type null; however, parameter $sLocale of Jaxon\Utils\Translation\Translator::setLocale() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            $this->setLocale(/** @scrutinizer ignore-type */ $xConfig->getOption('core.language'));
Loading history...
32
        }
33
    }
34
}
35