Completed
Pull Request — master (#3)
by Jonathan
02:54
created

EncryptionStatsTrait::returnHit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Jsq\Cache;
3
4
use Doctrine\Common\Cache\Cache;
5
6
trait EncryptionStatsTrait
7
{
8
    private $hits = 0;
9
    private $misses = 0;
10
    private $encryptionTime = 0.0;
11
12
    private function getEncryptionStats(array $inner = [])
13
    {
14
        return [
15
            Cache::STATS_HITS => $this->hits,
16
            Cache::STATS_MISSES => $this->misses,
17
            'encryption_time' => $this->encryptionTime,
18
        ] + $inner + [
19
            Cache::STATS_MEMORY_USAGE => null,
20
            Cache::STATS_MEMORY_AVAILABLE => null,
21
        ];
22
    }
23
24
    private function callAndTime(callable $func, array $args = [])
25
    {
26
        $start = microtime(true);
27
        $returnable = call_user_func_array($func, $args);
28
        $this->encryptionTime += microtime(true) - $start;
29
        return $returnable;
30
    }
31
32
    private function returnHit($hit)
33
    {
34
        $this->hits++;
35
        return $hit;
36
    }
37
38
    private function returnMiss($miss)
39
    {
40
        $this->misses++;
41
        return $miss;
42
    }
43
}
44