LocaleChangedEventSubscriber::changeLocale()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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