XSSFilterMiddleware::transform()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 3
c 3
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 2
crap 2.0625
1
<?php
2
3
namespace Alkhwlani\XssMiddleware;
4
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Foundation\Http\Middleware\TransformsRequest;
7
8
class XSSFilterMiddleware extends TransformsRequest
9
{
10
    /**
11
     * @var \Alkhwlani\XssMiddleware\Repository
0 ignored issues
show
Bug introduced by
The type Alkhwlani\XssMiddleware\Repository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
     */
13
    protected $config;
14
15
    /**
16
     * @var \GrahamCampbell\SecurityCore\Security
17
     */
18
    protected $security;
19
20 2
    public function __construct(Repository $config)
21
    {
22 2
        $this->security = app('security');
23 2
        $this->config = $config->get('xss-middleware');
24 2
    }
25
26
    /**
27
     * Transform the given value.
28
     *
29
     * @param string $key
30
     * @param mixed  $value
31
     *
32
     * @return mixed
33
     */
34 2
    protected function transform($key, $value)
35
    {
36 2
        if ($this->shouldIgnore($key, $value)) {
37
            return $value;
38
        }
39
40 2
        return $this->security->clean($value);
41
    }
42
43
    /**
44
     * determine if should ignore the field.
45
     *
46
     * @param $key
47
     * @param $value
48
     * @return bool
49
     */
50 2
    protected function shouldIgnore($key, $value): bool
51
    {
52 2
        return ! is_string($value) || in_array($key, $this->config['except'], true);
53
    }
54
}
55