Completed
Push — master ( dec0dd...e17ce1 )
by Mohamed
10:59 queued 08:07
created

Locale::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Middleware;
13
14
use Closure;
15
use Illuminate\Contracts\Auth\Guard;
16
use Illuminate\Http\Request;
17
18
/**
19
 * Locale is a Middleware class to set the locale for the current logged in user.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 */
23
class Locale
24
{
25
    /**
26
     * The Guard implementation.
27
     *
28
     * @var Guard
29
     */
30
    protected $auth;
31
32
    /**
33
     * Create a new filter instance.
34
     *
35
     * @param Guard $auth
36
     */
37 59
    public function __construct(Guard $auth)
38
    {
39 59
        $this->auth = $auth;
40 59
    }
41
42
    /**
43
     * Handle an incoming request.
44
     *
45
     * @param Request  $request
46
     * @param \Closure $next
47
     *
48
     * @return mixed
49
     */
50 59
    public function handle(Request $request, Closure $next)
51
    {
52 59
        if (!$this->auth->guest()) {
53 52
            app()->setLocale($this->auth->user()->language);
0 ignored issues
show
Bug introduced by
Accessing language on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
54
        }
55
56 59
        return $next($request);
57
    }
58
}
59