HitRate::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
 * Hit rate
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
 * Hit rate
15
 *
16
 * @author Tim Lochmüller
17
 */
18
class HitRate 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' => 'COUNT(DISTINCT allTrue.uid) / COUNT(DISTINCT hasGetRequireOnce.uid) as hitRate',
33
            'FROM'   => "(SELECT uid,request_hash,entry_identifier,called_method FROM tx_cachecheck_domain_model_log WHERE cache_name = '" . $cache->getName() . "' AND called_method IN ('has', 'get', 'requireOnce')) hasGetRequireOnce, (SELECT uid,request_hash,entry_identifier,called_method FROM tx_cachecheck_domain_model_log WHERE cache_name = '" . $cache->getName() . "' AND called_method IN ('hasTRUE', 'getTRUE', 'requireOnceTRUE')) allTrue",
34
            'WHERE'  => 'hasGetRequireOnce.entry_identifier = allTrue.entry_identifier AND hasGetRequireOnce.request_hash = allTrue.request_hash AND hasGetRequireOnce.uid < allTrue.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 * 100, 2) . '%';
49
    }
50
}
51