Passed
Push — master ( b86a9b...818b3e )
by Thierry
02:35
created

Translator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 4
c 0
b 0
f 0
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onChange() 0 6 2
A onChanges() 0 4 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\App\I18n;
4
5
/**
0 ignored issues
show
Coding Style introduced by
Block comments must be started with /*
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Translator
Loading history...
22
{
23
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $xConfig should have a doc-comment as per coding-style.
Loading history...
24
     * @inheritDoc
25
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
26
    public function onChanges(Config $xConfig)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
27
    {
28
        // Set the library language any time the config is changed.
29
        $this->setLocale($xConfig->getOption('core.language'));
0 ignored issues
show
Bug introduced by
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

29
        $this->setLocale(/** @scrutinizer ignore-type */ $xConfig->getOption('core.language'));
Loading history...
30
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $xConfig should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $sName should have a doc-comment as per coding-style.
Loading history...
33
     * @inheritDoc
34
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
35
    public function onChange(Config $xConfig, string $sName)
36
    {
37
        // Set the library language any time the config is changed.
38
        if($sName === 'core.language')
39
        {
40
            $this->setLocale($xConfig->getOption('core.language'));
0 ignored issues
show
Bug introduced by
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

40
            $this->setLocale(/** @scrutinizer ignore-type */ $xConfig->getOption('core.language'));
Loading history...
41
        }
42
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
43
}
44