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

EncryptionStatsTrait::callAndTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 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