RequestDataCollector::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace Rezzza\SecurityBundle\DataCollector;
4
5
use Doctrine\Common\Annotations\Reader as AnnotationReader;
6
use Doctrine\Common\Util\ClassUtils;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector as BaseRequestDataCollector;
10
use Rezzza\SecurityBundle\Controller\Annotations\ObfuscateRequest;
11
use Rezzza\SecurityBundle\Request\Obfuscator\ObfuscatorInterface;
12
13
class RequestDataCollector extends BaseRequestDataCollector
14
{
15
    /**
16
     * @var AnnotationReader
17
     */
18
    private $annotationReader;
19
20
    /**
21
     * @var Obfuscator
22
     */
23
    private $obfuscator;
24
25
    /**
26
     * @param AnnotationReader    $annotationReader annotationReader
27
     * @param ObfuscatorInterface $obfuscator       obfuscator
28
     */
29
    public function __construct(AnnotationReader $annotationReader, ObfuscatorInterface $obfuscator)
30
    {
31
        $this->annotationReader = $annotationReader;
32
        $this->obfuscator       = $obfuscator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $obfuscator of type object<Rezzza\SecurityBu...or\ObfuscatorInterface> is incompatible with the declared type object<Rezzza\SecurityBu...taCollector\Obfuscator> of property $obfuscator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
34
        parent::__construct();
35
    }
36
37
    public function collect(Request $request, Response $response, \Exception $exception = null)
38
    {
39
        parent::collect($request, $response, $exception);
40
41
        $controller = explode('::', $request->get('_controller'));
42
43
        if (count($controller) !== 2) {
44
            return;
45
        }
46
47
        $class            = new \ReflectionClass($controller[0]);
48
        $reflectionMethod = $class->getMethod($controller[1]);
49
        $annotation       = $this->annotationReader->getMethodAnnotation($reflectionMethod, '\Rezzza\SecurityBundle\Controller\Annotations\ObfuscateRequest');
50
51
        if ($annotation) {
52
            $this->data = $this->obfuscator->obfuscate($this->data, $annotation->getObfuscatedPatterns());
53
        }
54
    }
55
}
56