FileBackend   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A countTags() 0 4 1
A getExpires() 0 13 3
1
<?php
2
/**
3
 * Stats service for file backend
4
 *
5
 * @package CacheCheck\Service\Statistics
6
 * @author  Tim Lochmüller
7
 */
8
9
namespace HDNET\CacheCheck\Service\Statistics;
10
11
use HDNET\CacheCheck\Domain\Model\Cache;
12
use TYPO3\CMS\Core\Cache\Backend\FileBackend as CoreFileBackend;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
15
/**
16
 * Stats service for file backend
17
 *
18
 * @author Tim Lochmüller
19
 */
20
class FileBackend extends SimpleFileBackend
21
{
22
23
    /**
24
     * Get the number of tags
25
     *
26
     * @param Cache $cache
27
     *
28
     * @return int
29
     */
30
    public function countTags(Cache $cache)
31
    {
32
        return 'Not implement yet';
33
    }
34
35
    /**
36
     * Returns the average left lifetime of the cache entries
37
     *
38
     * @param Cache $cache
39
     *
40
     * @return int|null
41
     */
42
    public function getExpires(Cache $cache)
43
    {
44
        $cacheFileNames = glob(GeneralUtility::getFileAbsFileName($this->getCacheDirectory($cache) . '*'));
45
        if (!$cacheFileNames) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cacheFileNames of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
46
            return null;
47
        }
48
        $expireTimes = [];
49
        foreach ($cacheFileNames as $cacheFileName) {
50
            $index = (int)file_get_contents($cacheFileName, null, null, (filesize($cacheFileName) - CoreFileBackend::DATASIZE_DIGITS), CoreFileBackend::DATASIZE_DIGITS);
51
            $expireTimes[] = (int)file_get_contents($cacheFileName, null, null, $index, CoreFileBackend::EXPIRYTIME_LENGTH);
52
        }
53
        return (int)array_sum($expireTimes) / count($expireTimes);
54
    }
55
}
56