AverageCreationTime::getFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Get average creation 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
 * Get average creation time
15
 *
16
 * @author Tim Lochmüller
17
 */
18
class AverageCreationTime extends AbstractAnalyzer
19
{
20
21
    /**
22
     * Get the given KPI
23
     *
24
     * @param Cache $cache
25
     *
26
     * @return mixed
27
     */
28
    public function getKpi(Cache $cache)
29
    {
30
        $queryValues = [
31
            'SELECT' => 'AVG(t_set.timestamp - t_has.timestamp) as creation_time',
32
            'FROM'   => 'tx_cachecheck_domain_model_log t_has, tx_cachecheck_domain_model_log t_set',
33
            'WHERE'  => "t_has.cache_name = '" . $cache->getName() . "' AND t_has.called_method = 'has' AND t_set.cache_name = '" . $cache->getName() . "' AND t_set.called_method = 'set' AND t_set.entry_size > 0 AND t_has.request_hash = t_set.request_hash AND t_has.entry_identifier = t_set.entry_identifier AND t_has.uid < t_set.uid",
34
        ];
35
        return (float)$this->getDynamicFromDatabase($queryValues);
36
    }
37
38
    /**
39
     * Format the given KPI
40
     *
41
     * @param mixed $kpi
42
     *
43
     * @return string
44
     */
45
    public function getFormat($kpi)
46
    {
47
        return round($kpi, 2) . ' milliseconds';
48
    }
49
}
50