Completed
Push — master ( 4aaab4...5f2b12 )
by
unknown
01:34 queued 10s
created

IntlExtension::getLanguageName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\TranslationBundle\Twig\Extension;
15
16
use Symfony\Component\Intl\Exception\MissingResourceException;
17
use Symfony\Component\Intl\Languages;
18
use Twig\Extension\AbstractExtension;
19
use Twig\TwigFilter;
20
21
final class IntlExtension extends AbstractExtension
22
{
23
    /** @return TwigFilter[] */
24
    public function getFilters(): array
25
    {
26
        return [
27
            new TwigFilter('sonata_language_name', [$this, 'getLanguageName']),
28
        ];
29
    }
30
31
    /**
32
     * @see https://github.com/twigphp/intl-extra/blob/v3.0.3/src/IntlExtension.php#L185
33
     */
34
    public function getLanguageName(string $language, string $locale): string
35
    {
36
        try {
37
            return Languages::getName($language, $locale);
38
        } catch (MissingResourceException $exception) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Intl\E...issingResourceException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
39
            return $language;
40
        }
41
    }
42
}
43