Completed
Push — master ( e0306e...074f1a )
by Jonathan
8s
created

EncryptionStatsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 39
ccs 21
cts 21
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEncryptionStats() 0 12 1
A callAndTime() 0 7 1
A returnHit() 0 5 1
A returnMiss() 0 5 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 153
    private function getEncryptionStats(array $inner = [])
13
    {
14
        return [
15 153
            'hits' => $this->hits,
16 153
            'misses' => $this->misses,
17 153
            'encryption_time' => $this->encryptionTime,
18 153
        ] + $inner + [
19 153
            'uptime' => null,
20 153
            'memory_usage' => null,
21 153
            'memory_available' => null,
22 153
        ];
23
    }
24
25 288
    private function callAndTime(callable $func, array $args = [])
26
    {
27 288
        $start = microtime(true);
28 288
        $returnable = call_user_func_array($func, $args);
29 255
        $this->encryptionTime += microtime(true) - $start;
30 255
        return $returnable;
31
    }
32
33 153
    private function returnHit($hit)
34
    {
35 153
        $this->hits++;
36 153
        return $hit;
37
    }
38
39 111
    private function returnMiss($miss)
40 3
    {
41 111
        $this->misses++;
42 111
        return $miss;
43
    }
44
}
45