AppLocaleUpdated   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 13 2
1
<?php
2
3
namespace AlexJoffroy\Localization\Listeners;
4
5
use Illuminate\Foundation\Events\LocaleUpdated;
6
use AlexJoffroy\Localization\Localization;
7
8
class AppLocaleUpdated
9
{
10
    /** @var \AlexJoffroy\Localization\Localization */
11
    protected $localization;
12
    
13 22
    public function __construct(Localization $localization)
14
    {
15 22
        $this->localization = $localization;
16 22
    }
17
18 22
    public function handle(LocaleUpdated $event)
19
    {
20 22
        $supportedLocale = $this->localization->getSupportedLocale($event->locale);
21 22
        $constants = collect($supportedLocale->get('constants', []));
22 22
        $regionalCode = $supportedLocale->get('regional_code');
23 22
        $charset = $supportedLocale->get('charset', false);
24
25 22
        $localeCode = $charset ? "$regionalCode.$charset" : $regionalCode;
26
27
        $constants->each(function ($constant) use ($localeCode) {
28 22
            setlocale(constant($constant), $localeCode);
29 22
        });
30 22
    }
31
}
32