Completed
Push — master ( 1b7c9c...cf42d1 )
by Avtandil
03:25
created

MultiLang::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
/*
3
 * This file is part of the Laravel MultiLang package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\LaravelMultiLang\Middleware;
12
13
use Closure;
14
use Illuminate\Foundation\Application;
15
use Illuminate\Http\Request;
16
use Illuminate\Routing\Redirector;
17
use Longman\LaravelMultiLang\Multilang as MultilangLib;
18
19
class MultiLang
20
{
21
22 4
    public function __construct(Application $app, Redirector $redirector, MultilangLib $multilang)
23
    {
24 4
        $this->app        = $app;
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25 4
        $this->redirector = $redirector;
0 ignored issues
show
Bug introduced by
The property redirector does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26 4
        $this->multilang  = $multilang;
0 ignored issues
show
Bug introduced by
The property multilang does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27 4
    }
28
29
    /**
30
     * Handle an incoming request.
31
     *
32
     * @param  \Illuminate\Http\Request $request
33
     * @param  \Closure                 $next
34
     * @return mixed
35
     */
36 4
    public function handle($request, Closure $next)
37
    {
38 4
        $url = $this->multilang->getRedirectUrl($request);
39 4
        if ($url !== null) {
40 3
            return $this->redirector->to($url);
41
        }
42
43 1
        $this->app->setLocale($this->multilang->getLocale());
44
45 1
        return $next($request);
46
    }
47
}
48