SmsSenderDataCollector   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 62
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getTime() 0 4 1
A getSmsData() 0 4 1
A getSmsCount() 0 4 1
A retrieveSmsList() 0 4 1
A collect() 0 8 1
A computeTime() 0 10 2
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