AverageCreationTime   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getKpi() 0 9 1
A getFormat() 0 4 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