RequestDataCollector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A collect() 0 18 3
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