LocaleChangedEventSubscriber   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A subscribe() 0 3 1
A changeLocale() 0 5 1
1
<?php
2
3
namespace mindtwo\LaravelMultilingual\Listeners;
4
5
use Illuminate\Support\Facades\App;
6
use Illuminate\Foundation\Events\LocaleUpdated;
7
use mindtwo\LaravelMultilingual\Services\Locale;
8
9
class LocaleChangedEventSubscriber
10
{
11
    /**
12
     * Handle the event.
13
     *
14
     * @param object $event
15
     *
16
     * @return string
17
     */
18
    public static function changeLocale($event): string
19
    {
20
        App::make(Locale::class)->setCurrentLocaleAttribute($event->locale);
21
22
        return $event->locale;
23
    }
24
25
    /**
26
     * Register the listeners for the subscriber.
27
     *
28
     * @param object $events
29
     */
30
    public function subscribe($events)
31
    {
32
        $events->listen(LocaleUpdated::class, [self::class, 'changeLocale']);
33
    }
34
}
35