SmsSenderDataCollector::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DoS\SMSBundle\DataCollector;
4
5
use DoS\SMSBundle\SMS\Logger;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9
10
class SmsSenderDataCollector extends DataCollector
11
{
12
    protected $logger;
13
14
    public function __construct(Logger $logger)
15
    {
16
        $this->logger = $logger;
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function collect(Request $request, Response $response, \Exception $exception = null)
23
    {
24
        $this->data = array(
25
            'smsData' => $list = $this->retrieveSmsList(),
26
            'smsCount' => count($list),
27
            'time' => $this->computeTime(),
28
        );
29
    }
30
31
    /**
32
     * Returns the collector name.
33
     *
34
     * @return string The collector name.
35
     */
36
    public function getName()
37
    {
38
        return 'dos_sms_sender';
39
    }
40
41
    public function getTime()
42
    {
43
        return $this->data['time'];
44
    }
45
46
    public function getSmsData()
47
    {
48
        return $this->data['smsData'];
49
    }
50
51
    public function getSmsCount()
52
    {
53
        return $this->data['smsCount'];
54
    }
55
56
    protected function computeTime()
57
    {
58
        $total = 0;
59
60
        foreach ($this->logger->getSms() as $data) {
61
            $total += $data['duration'];
62
        }
63
64
        return $total;
65
    }
66
67
    protected function retrieveSmsList()
68
    {
69
        return $this->logger->getSms();
70
    }
71
}
72