StatefulTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 15
dl 0
loc 51
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setState() 0 9 2
A getStateTime() 0 3 1
A setId() 0 5 1
A getId() 0 3 1
A getStateMessage() 0 3 1
A getState() 0 3 1
1
<?php namespace Comodojo\Cache\Traits;
2
3
use \DateTime;
4
5
/**
6
 * @package     Comodojo Cache
7
 * @author      Marco Giovinazzi <[email protected]>
8
 * @license     MIT
9
 *
10
 * LICENSE:
11
 *
12
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
 * THE SOFTWARE.
19
 */
20
21
trait StatefulTrait {
22
23
    private $id;
24
25
    private $state = 0;
26
27
    private $state_message;
28
29
    private $state_time;
30
31 356
    protected function setId($id) {
32
33 356
        $this->id = $id;
34
35 356
        return $this;
36
37
    }
38
39 103
    public function getId() {
40
41 103
        return $this->id;
42
43
    }
44
45 112
    public function getState() {
46
47 112
        return $this->state;
48
49
    }
50
51 31
    public function getStateMessage() {
52
53 31
        return $this->state_message;
54
55
    }
56
57 26
    public function getStateTime() {
58
59 26
        return $this->state_time;
60
61
    }
62
63 356
    public function setState($state, $message = null) {
64
65 356
        $this->state = $state === self::CACHE_SUCCESS ? self::CACHE_SUCCESS : self::CACHE_ERROR;
0 ignored issues
show
Bug introduced by
The constant Comodojo\Cache\Traits\StatefulTrait::CACHE_SUCCESS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant Comodojo\Cache\Traits\StatefulTrait::CACHE_ERROR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
66
67 356
        $this->state_message = $message;
68
69 356
        $this->state_time = new DateTime('now');
70
71 356
        return $this;
72
73
    }
74
75
}
76