Passed
Push — master ( ebde88...d0f1c0 )
by Stephen
13:30 queued 10:34
created

HasAutoCacheKey::cacheKey()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 15
rs 10
1
<?php
2
3
namespace Sfneal\Caching\Traits;
4
5
trait HasAutoCacheKey
6
{
7
    use IsCacheable;
8
9
    /**
10
     * Retrieve the Query cache key.
11
     *
12
     * @return string
13
     */
14
    public function cacheKey(): string
15
    {
16
        $reflection = (new \ReflectionClass($this));
17
18
        $key = 'auto_'.strtolower(str_replace('\\', '-', $reflection->getName()));
19
20
        if (count($reflection->getProperties())) {
21
            foreach ($reflection->getProperties() as $property) {
22
                if ($property->getName() != 'ttl') {
23
                    $key .= ':'.$this->{$property->getName()};
24
                }
25
            }
26
        }
27
28
        return $key;
29
    }
30
}
31