LogTime::getKpi()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
/**
3
 * Log 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
use HDNET\CacheCheck\Service\FormatService;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
15
/**
16
 * Log time
17
 *
18
 * @author Tim Lochmüller
19
 */
20
class LogTime extends AbstractAnalyzer
21
{
22
23
    /**
24
     * Internal runtime cache
25
     *
26
     * @var array
27
     */
28
    protected static $internalCache = [];
29
30
    /**
31
     * Get the given KPI
32
     *
33
     * @param Cache $cache
34
     *
35
     * @return mixed
36
     * @throws \HDNET\CacheCheck\Exception
37
     */
38
    public function getKpi(Cache $cache)
39
    {
40
        if (isset(self::$internalCache[$cache->getName()])) {
41
            return self::$internalCache[$cache->getName()];
42
        }
43
        $startTime = $this->getAnalyzer('StartTime');
44
        $endTime = $this->getAnalyzer('EndTime');
45
        self::$internalCache[$cache->getName()] = $endTime->getKpi($cache) - $startTime->getKpi($cache);
46
        return self::$internalCache[$cache->getName()];
47
    }
48
49
    /**
50
     * Format the given KPI
51
     *
52
     * @param mixed $kpi
53
     *
54
     * @return string
55
     */
56
    public function getFormat($kpi)
57
    {
58
        $formatService = GeneralUtility::makeInstance(FormatService::class);
59
        return $formatService->formatSeconds($kpi);
60
    }
61
}
62