Completed
Push — master ( 815b6a...60c4a7 )
by ARCANEDEV
05:35
created

SeoSpamBlockerMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace Arcanesoft\Seo\Http\Middleware;
2
3
use Arcanedev\SpamBlocker\Contracts\SpamBlocker;
4
use Closure;
5
use Illuminate\Http\Request;
6
7
/**
8
 * Class     SeoSpamBlockerMiddleware
9
 *
10
 * @package  Arcanesoft\Seo\Http\Middleware
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class SeoSpamBlockerMiddleware
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /** @var  \Arcanedev\SpamBlocker\Contracts\SpamBlocker */
20
    protected $blocker;
21
22
    /* ------------------------------------------------------------------------------------------------
23
     |  Constructor
24
     | ------------------------------------------------------------------------------------------------
25
     */
26 8
    public function __construct(SpamBlocker $blocker)
27
    {
28 8
        $this->blocker = $blocker;
29 8
    }
30
31
    /* ------------------------------------------------------------------------------------------------
32
     |  Main Functions
33
     | ------------------------------------------------------------------------------------------------
34
     */
35
    /**
36
     * Handle an incoming request.
37
     *
38
     * @param  \Illuminate\Http\Request  $request
39
     * @param  \Closure                  $next
40
     *
41
     * @return mixed
42
     */
43 8
    public function handle(Request $request, Closure $next)
44
    {
45 8
        if ($this->blocker->isBlocked($request->headers->get('referer'))) {
46 4
            return response('Unauthorized.', 401);
47
        }
48
49 4
        return $next($request);
50
    }
51
}
52