TraceCollector   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getTraces() 0 4 1
B onTrace() 0 20 6
A collect() 0 3 1
A getName() 0 4 1
1
<?php
2
3
namespace PedroTroller\TraceDebug\DataCollector;
4
5
use PedroTroller\TraceDebug\TraceHandler;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9
10
class TraceCollector extends DataCollector implements TraceHandler
11
{
12
    public function __construct()
13
    {
14
        $this->data['identified'] = [];
15
        $this->data['anonymous']  = [];
16
    }
17
18
    /**
19
     * @return array
20
     */
21
    public function getTraces()
22
    {
23
        return $this->data;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function onTrace(array $trace, $identifier = null)
30
    {
31
        foreach ($trace as $index => $call) {
32
            foreach ($call['args'] as $position => $arg) {
33
                $call['args'][$position] = $this->varToString($arg);
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\HttpKe...ollector::varToString() has been deprecated with message: Deprecated since version 3.2, to be removed in 4.0. Use cloneVar() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
34
            }
35
            $trace[$index] = $call;
36
        }
37
38
        $side = null === $identifier ? 'anonymous' : 'identified';
39
40
        if (null === $identifier) {
41
            $this->data[$side][] = $trace;
42
        } else {
43
            if (false === array_key_exists($identifier, $this->data[$side])) {
44
                $this->data[$side][$identifier] = [];
45
            }
46
            $this->data[$side][$identifier][] = $trace;
47
        }
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function collect(Request $request, Response $response, \Exception $exception = null)
54
    {
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getName()
61
    {
62
        return 'trace_debug';
63
    }
64
}
65