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

SeoSpamBlockerMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 2
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