Completed
Push — master ( 95dfed...c235b9 )
by Ryan
02:07
created

SetLocale::handle()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
rs 9.2
cc 4
eloc 6
nc 2
nop 4
1
<?php namespace Anomaly\PreferencesModule\Preference\Listener\Command;
2
3
use Anomaly\PreferencesModule\Preference\Contract\PreferenceRepositoryInterface;
4
use Illuminate\Config\Repository;
5
use Illuminate\Contracts\Bus\SelfHandling;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Http\Request;
8
9
/**
10
 * Class SetLocale
11
 *
12
 * @link          http://pyrocms.com/
13
 * @author        PyroCMS, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 * @package       Anomaly\PreferencesModule\Preference\Listener\Command
16
 */
17
class SetLocale implements SelfHandling
18
{
19
20
    /**
21
     * Handle the command.
22
     *
23
     * @param Application                   $app
24
     * @param Repository                    $config
25
     * @param Request                       $request
26
     * @param PreferenceRepositoryInterface $preferences
27
     */
28
    function handle(Application $app, Repository $config, Request $request, PreferenceRepositoryInterface $preferences)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
    {
30
        if (!defined('LOCALE') && $locale = $preferences->value(
31
                'streams::' . ($request->segment(1) == 'admin' ? 'admin' : 'public') . '_locale'
32
            )
33
        ) {
34
            define('LOCALE', $locale);
35
            $app->setLocale($locale);
36
            $config->set('app.locale', $locale);
37
        }
38
    }
39
}
40