ClientDataCollector::collect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
3
/*
4
 * This file is part of the MobileNotifBundle package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace LinkValue\MobileNotifBundle\DataCollector;
11
12
use LinkValue\MobileNotifBundle\Profiler\ClientProfilerInterface;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpFoundation\Response;
15
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
16
17
/**
18
 * ClientDataCollector.
19
 *
20
 * @package MobileNotifBundle
21
 * @author  Jamal Youssefi <[email protected]>
22
 * @author  Valentin Coulon <[email protected]>
23
 */
24
class ClientDataCollector extends DataCollector
25
{
26
    /**
27
     * @var ClientProfilerInterface
28
     */
29
    private $profiler;
30
31
    /**
32
     * @param ClientProfilerInterface $profiler
33
     */
34
    public function __construct(ClientProfilerInterface $profiler)
35
    {
36
        $this->profiler = $profiler;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getName()
43
    {
44
        return 'link_value_mobile_notif';
45
    }
46
47
    /**
48
     * @param Request         $request
49
     * @param Response        $response
50
     * @param \Exception|null $exception
51
     */
52
    public function collect(Request $request, Response $response, \Exception $exception = null)
53
    {
54
        $this->data['push_calls'] = $this->profiler->getCalls();
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60
    public function getCalls()
61
    {
62
        return $this->data['push_calls'];
63
    }
64
65
    /**
66
     * @return int
67
     */
68
    public function getCountCalls()
69
    {
70
        return count($this->data['push_calls']);
71
    }
72
73
    /**
74
     * @return int
75
     */
76
    public function getCountErrors()
77
    {
78
        $errors = 0;
79
        foreach ($this->data['push_calls'] as $call) {
80
            if ($call['error'] == true) {
81
                ++$errors;
82
            }
83
        }
84
85
        return $errors;
86
    }
87
88
    /**
89
     * @return int
90
     */
91
    public function getTotalTime()
92
    {
93
        $time = 0;
94
        foreach ($this->data['push_calls'] as $call) {
95
            $time += $call['duration'];
96
        }
97
98
        return $time;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function getMemoryUsage()
105
    {
106
        $memory = 0;
107
        foreach ($this->data['push_calls'] as $call) {
108
            $memory += $call['memory_use'];
109
        }
110
111
        return $memory;
112
    }
113
}
114