Completed
Push — master ( f7b23b...c89e2b )
by Arthur
06:56
created

HSTSHeaders   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 22 3
1
<?php namespace App\Http\Middleware;
2
3
class HSTSHeaders
4
{
5
    /**
6
     * Handle an incoming request.
7
     *
8
     * @param  \Illuminate\Http\Request $request
9
     * @param  \Closure                 $next
10
     * @return mixed
11
     */
12
    public function handle($request, Closure $next)
13
    {
14
        $response = $next($request);
15
16
        if ($response instanceof RedirectResponse) {
0 ignored issues
show
Bug introduced by
The class App\Http\Middleware\RedirectResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
17
            return $response;
18
        }
19
20
        $cacheDays = 182; //180 days minimum reccomended by SSL Labs
21
        $maxAge     = 60 * 60 * 24 * $cacheDays;
22
23
        //Domains on which we want to serve the header
24
        // be careful with this as it can't be undone
25
        // the domain must always be available over https
26
        $protectedHosts = ['monitor.vestd.com'];
27
28
        if (in_array($request->getHttpHost(), $protectedHosts)) {
29
            return $response->header('Strict-Transport-Security', 'max-age=' . $maxAge . '; preload');
30
        }
31
32
        return $response;
33
    }
34
}