TraceCollector::getTraces()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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