Completed
Branch v1.x-dev (6fcd50)
by Benjamin
04:47
created

LocaleHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 16
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getLocalizedRoutes() 0 11 2
A getAvailableLocales() 0 3 1
1
<?php
2
3
namespace Obblm\Core\Helper;
4
5
use Symfony\Component\Routing\RouterInterface;
6
7
class LocaleHelper
8
{
9
    private $router = null;
10
    private $available_locales = null;
11
12
    public function __construct(RouterInterface $router, $defaultLocale = "en")
13
    {
14
        $this->router = $router;
15
        $this->available_locales = [$defaultLocale];
16
17
        $locales = $router->getRouteCollection()->get('obblm_locale_switch')->getRequirement('_locale');
18
19
        if($locales) {
20
            $this->available_locales = explode('|', $locales);
21
        }
22
    }
23
24
    /**
25
     * @return false|string[]
26
     */
27
    public function getAvailableLocales()
28
    {
29
        return $this->available_locales;
30
    }
31
32
    /**
33
     * @return false|string[]
34
     */
35
    public function getLocalizedRoutes()
36
    {
37
        $routes = [];
38
        foreach ($this->available_locales as $locale)
39
        {
40
            $routes[] = [
41
                'route' => $this->router->generate('obblm_locale_switch', ['_locale' => $locale]),
42
                '_locale' => $locale,
43
            ];
44
        }
45
        return $routes;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $routes returns an array which contains values of type array<string,mixed|string> which are incompatible with the documented value type string.
Loading history...
46
    }
47
}
48