AverageSelectionTime   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getKpi() 0 9 1
A getFormat() 0 4 1
1
<?php
2
/**
3
 * Average selection time
4
 *
5
 * @package CacheCheck\Service\Analyzer
6
 * @author  Tim Lochmüller
7
 */
8
9
namespace HDNET\CacheCheck\Service\Analyzer;
10
11
use HDNET\CacheCheck\Domain\Model\Cache;
12
13
/**
14
 * Average selection time
15
 *
16
 * @author Tim Lochmüller
17
 */
18
class AverageSelectionTime extends AbstractAnalyzer
19
{
20
21
    /**
22
     * Get the given KPI
23
     *
24
     * @param Cache $cache
25
     *
26
     * @return mixed
27
     * @throws \HDNET\CacheCheck\Exception
28
     */
29
    public function getKpi(Cache $cache)
30
    {
31
        $queryValues = [
32
            'SELECT' => 'AVG(t_getAfter.timestamp - t_get.timestamp) as selection_time',
33
            'FROM'   => 'tx_cachecheck_domain_model_log t_get, tx_cachecheck_domain_model_log t_getAfter',
34
            'WHERE'  => "t_get.cache_name = '" . $cache->getName() . "' AND t_get.called_method = 'get' AND t_getAfter.cache_name = '" . $cache->getName() . "' AND t_getAfter.called_method = 'getAfter' AND t_get.request_hash = t_getAfter.request_hash AND t_get.entry_identifier = t_getAfter.entry_identifier AND t_get.uid < t_getAfter.uid",
35
        ];
36
        return (float)$this->getDynamicFromDatabase($queryValues);
37
    }
38
39
    /**
40
     * Format the given KPI
41
     *
42
     * @param mixed $kpi
43
     *
44
     * @return string
45
     */
46
    public function getFormat($kpi)
47
    {
48
        return round($kpi, 2) . ' milliseconds';
49
    }
50
}
51