CrawlingRobots::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.7666
cc 4
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Http\Middleware;
6
7
use Closure;
8
use Exception;
9
use Illuminate\Http\Request;
10
11
class CrawlingRobots
12
{
13
    protected $response;
14
15
    public function handle(Request $request, Closure $next)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
16
    {
17
        $this->response = $next($request);
18
        $shouldIndex = $this->shouldIndex($request);
19
20
        if (is_bool($shouldIndex)) {
21
            return $this->responseWithRobots($shouldIndex ? 'all' : 'none');
22
        }
23
24
        if (is_string($shouldIndex)) {
25
            return $this->responseWithRobots($shouldIndex);
26
        }
27
28
        throw new Exception(trans('cortex/foundation::messages.invalid_indexing_rule'));
29
    }
30
31
    protected function responseWithRobots(string $contents)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
32
    {
33
        $this->response->headers->set('x-robots-tag', $contents, false);
34
35
        return $this->response;
36
    }
37
38
    /**
39
     * @return string|bool
40
     */
41
    protected function shouldIndex(Request $request)
42
    {
43
        return app()->environment('production') && ! in_array($request->route('accessarea'), array_keys(config('cortex.foundation.route.prefix')));
44
    }
45
}
46