Completed
Push — 2.x ( 11343a...e4dad7 )
by Jindřich
02:34
created

SkautisDataCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 47.62%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 8
c 8
b 0
f 0
lcom 1
cbo 4
dl 0
loc 78
rs 10
ccs 10
cts 21
cp 0.4762

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A collect() 0 17 1
A __call() 0 4 1
A getRequests() 0 4 1
A getRequestCount() 0 4 1
A getTotalTime() 0 9 2
A getName() 0 4 1
1
<?php
2
3
namespace SkautisBundle\Profiler;
4
5
use Skautis\Skautis;
6
use Skautis\SkautisQuery;
7
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Sbira data o skautisu pro zobrazeni v profileru
13
 */
14
class SkautisDataCollector extends DataCollector
15
{
16
17
    /**
18
     * @var Skautis
19
     */
20
    protected $skautis;
21
22 2
    public function __construct(Skautis $skautis)
23
    {
24 2
        $this->skautis = $skautis;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 2
    public function collect(Request $request, Response $response, \Exception $exception = null)
31
    {
32
	    $config = $this->skautis->getConfig();
33 2
        $this->data = [
34 2
    	    'queries'           => $this->skautis->getDebugLog(),
35 2
            'app_id'            => $config->getAppId(),
36 2
	        'test_mode'         => $config->isTestMode(),
37 2
	        'cache'             => $config->getCache(),
38 2
	        'compression'       => $config->getCompression(),
39
	        'role_id'           => $this->skautis->getUser()->getRoleId(),
40
	        'unit_id'           => $this->skautis->getUser()->getUnitId(),
41
	        'token'             => $this->skautis->getUser()->getLoginId(),
42
	        'is_logged_in'      => $this->skautis->getUser()->isLoggedIn(),
43
	        'logout_date'       => $this->skautis->getUser()->getLogoutDate(),
44 2
	        'maintenance'       => $this->skautis->isMaintenance(),
45
        ];
46
    }
47
48
    public function __call($method, $args)
49
    {
50
        return $this->data["$method"];
51
    }
52
53
    /**
54
     * Ziska vsechny SkautisQuery
55
     * @return SkautisQuery[]
56
     */
57
    public function getRequests()
58
    {
59
	    return $this->data['queries'];
60
    }
61
62
    /**
63
     * Pocet requestu
64
     * @return int
65
     */
66
    public function getRequestCount()
67
    {
68
	    return count($this->data['queries']);
69
    }
70
71
    /**
72
     * @return int Miliseconds
73
     */
74
    public function getTotalTime()
75
    {
76
        $totalTime = 0;
77
        foreach ($this->data['queries'] as $query) {
78
            $totalTime += $query->time;
79
        }
80
81
        return $totalTime * 1000;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public function getName()
88
    {
89
        return 'skautis_collector';
90
    }
91
}
92