Completed
Push — 2.4 ( 163f78...a11563 )
by James
71:34 queued 69:17
created

RemoteUserAuthenticate::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 12
ccs 0
cts 6
cp 0
crap 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Cachet.
5
 *
6
 * (c) Alt Three Services Limited
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 CachetHQ\Cachet\Http\Middleware;
13
14
use CachetHQ\Cachet\Models\User;
15
use Closure;
16
use Illuminate\Contracts\Auth\Guard;
17
use Illuminate\Http\Request;
18
19
class RemoteUserAuthenticate
20
{
21
    /**
22
     * Create a new remote user authenticate instance.
23
     *
24
     * @param \Illuminate\Contracts\Auth\Guard $auth
25
     *
26
     * @return void
27
     */
28
    public function __construct(Guard $auth)
29
    {
30
        $this->auth = $auth;
0 ignored issues
show
Bug introduced by James Brooks
The property auth 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...
31
    }
32
33
    /**
34
     * Handle an incoming request.
35
     *
36
     * @param \Illuminate\Http\Request $request
37
     * @param \Closure                 $next
38
     *
39
     * @return mixed
40
     */
41
    public function handle(Request $request, Closure $next)
42
    {
43
        if ($remoteUser = $request->server('REMOTE_USER')) {
44
            $user = User::where('email', '=', $remoteUser)->first();
45
46
            if ($user instanceof User && $this->auth->guest()) {
47
                $this->auth->login($user);
48
            }
49
        }
50
51
        return $next($request);
52
    }
53
}
54