Passed
Push — master ( 6692d3...4dd3a5 )
by Sébastien
02:56 queued 15s
created

CacheKey   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 18
c 1
b 0
f 0
dl 0
loc 89
ccs 22
cts 22
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setLifetime() 0 4 1
A namespace() 0 3 2
A setNamespace() 0 4 1
A valid() 0 3 1
A lifetime() 0 3 1
A key() 0 3 2
A setKey() 0 4 1
1
<?php
2
3
namespace Bdf\Prime\Cache;
4
5
/**
6
 * Class CacheKey
7
 */
8
final class CacheKey
9
{
10
    /**
11
     * @var string|callable
12
     */
13
    private $namespace;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
14
15
    /**
16
     * @var string|callable
17
     */
18
    private $key;
19
20
    /**
21
     * @var integer
0 ignored issues
show
introduced by
Expected "int" but found "integer" for @var tag in member variable comment
Loading history...
22
     */
23
    private $lifetime = 0;
24
25
    /**
26
     * CacheKey constructor.
27
     * @param callable|string $namespace
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
28
     * @param callable|string $key
29
     * @param int $lifetime
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
30
     */
31 556
    public function __construct($namespace = null, $key = null, int $lifetime = 0)
32
    {
33 556
        $this->namespace = $namespace;
34 556
        $this->key = $key;
35 556
        $this->lifetime = $lifetime;
36 556
    }
37
38
    /**
39
     * @return string
40
     */
41 34
    public function namespace(): string
42
    {
43 34
        return is_string($this->namespace) ? $this->namespace : ($this->namespace)();
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
44
    }
45
46
    /**
47
     * @param string|callable $namespace
48
     *
49
     * @return $this
50
     */
51 11
    public function setNamespace($namespace): CacheKey
52
    {
53 11
        $this->namespace = $namespace;
54 11
        return $this;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 34
    public function key(): ?string
61
    {
62 34
        return is_string($this->key) ? $this->key : ($this->key)();
0 ignored issues
show
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
63
    }
64
65
    /**
66
     * @param string|callable $key
67
     *
68
     * @return $this
69
     */
70 11
    public function setKey($key): CacheKey
71
    {
72 11
        $this->key = $key;
73 11
        return $this;
74
    }
75
76
    /**
77
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
78
     */
79 17
    public function lifetime(): int
80
    {
81 17
        return $this->lifetime;
82
    }
83
84
    /**
85
     * @param int $lifetime
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
86
     * @return $this
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
87
     */
88 1
    public function setLifetime(int $lifetime): CacheKey
89
    {
90 1
        $this->lifetime = $lifetime;
91 1
        return $this;
92
    }
93
94 23
    public function valid(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function valid()
Loading history...
introduced by
Missing function doc comment
Loading history...
95
    {
96 23
        return !empty($this->key());
97
    }
98
}
99