RobotsMiddleware   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 4
A responseWithRobots() 0 6 1
A shouldIndex() 0 4 1
1
<?php
2
3
namespace Spatie\RobotsMiddleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class RobotsMiddleware
9
{
10
    protected $response;
11
12
    public function handle(Request $request, Closure $next)
13
    {
14
        $this->response = $next($request);
15
16
        $shouldIndex = $this->shouldIndex($request);
17
18
        if (is_bool($shouldIndex)) {
19
            return $this->responseWithRobots($shouldIndex ? 'all' : 'none');
20
        }
21
22
        if (is_string($shouldIndex)) {
23
            return $this->responseWithRobots($shouldIndex);
24
        }
25
26
        throw InvalidIndexRule::requiresBooleanOrString();
27
    }
28
29
    protected function responseWithRobots(string $contents)
30
    {
31
        $this->response->headers->set('x-robots-tag', $contents, false);
32
33
        return $this->response;
34
    }
35
36
    /**
37
     * @return string|bool
38
     */
39
    protected function shouldIndex(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        return true;
42
    }
43
}
44