XSSFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 3
1
<?php
2
namespace App\Http\Middleware;
3
4
use Closure;
5
6
class XSSFilter
7
{
8
    /**
9
     * Handle an incoming request.
10
     *
11
     * @param  \Illuminate\Http\Request  $request
12
     * @param  \Closure  $next
13
     * @return mixed
14
     */
15
    public function handle($request, Closure $next)
16
    {
17
        if (!in_array(strtoupper($request->method(), ['PUT', 'POST']))) {
0 ignored issues
show
Unused Code introduced by
The call to strtoupper() has too many arguments starting with array('PUT', 'POST'). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        if (!in_array(/** @scrutinizer ignore-call */ strtoupper($request->method(), ['PUT', 'POST']))) {

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
The call to in_array() has too few arguments starting with haystack. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        if (!/** @scrutinizer ignore-call */ in_array(strtoupper($request->method(), ['PUT', 'POST']))) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
18
            return $next[$request];
19
        }
20
21
        $input = $request->all();
22
23
        array_walk_recursive($input, function(&$input) {
24
            if (is_string($input)) $input = htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
25
        });
26
27
        $request->merge($input);
28
29
        return $next[$request];
30
    }
31
}
32