Gaming::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace SiObjects\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Contracts\Routing\ResponseFactory;
8
use Illuminate\Support\Facades\Config;
9
use Illuminate\Support\Facades\Cookie;
10
11
class Gaming
12
{
13
    /**
14
     * The Guard implementation.
15
     *
16
     * @var Guard
17
     */
18
    protected $auth;
19
20
    /**
21
     * The response factory implementation.
22
     *
23
     * @var ResponseFactory
24
     */
25
    protected $response;
26
27
    /**
28
     * Create a new filter instance.
29
     *
30
     * @param  Guard           $auth
31
     * @param  ResponseFactory $response
32
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
33
     */
34
    public function __construct(Guard $auth,
35
        ResponseFactory $response
36
    ) {
37
        $this->auth = $auth;
38
        $this->response = $response;
39
    }
40
41
    /**
42
     * Handle an incoming request.
43
     *
44
     * @param \Illuminate\Http\Request $request
45
     * @param \Closure                 $next
46
     *
47
     * @return mixed
48
     */
49
    public function handle($request, Closure $next)
50
    {
51
        if ($this->auth->check()) {
52
            $language = (int) $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...
Unused Code introduced by
$language is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53
        }
54
55
        if (Cookie::has('language')) {
56
            Config::set('app.locale', Cookie::get('language'));
57
            app()->setLocale(Cookie::get('language'));
58
        }
59
60
        if ($request->session()->has('language')) {
61
            Config::set('app.locale', $request->session()->get('language'));
62
            app()->setLocale($request->session()->get('language'));
63
        }
64
65
        return $next($request);
66
    }
67
}
68