State   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 62
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A is() 0 4 1
A setDeleted() 0 8 2
A setDeleting() 0 4 1
A setNew() 0 5 1
A setLoaded() 0 5 1
A setDirty() 0 4 1
A setEmpty() 0 4 1
A set() 0 4 1
1
<?php
2
3
namespace As3\Modlr\Models;
4
5
use As3\Modlr\Store;
6
use As3\Modlr\Metadata\EntityMetadata;
7
8
/**
9
 * Represents a data record from a persistence (database) layer.
10
 *
11
 * @author Jacob Bare <[email protected]>
12
 */
13
class State
14
{
15
    private $status = [
16
        'empty'     => false,
17
        'loaded'    => false,
18
        'dirty'     => false,
19
        'deleting'  => false,
20
        'deleted'   => false,
21
        'new'       => false,
22
    ];
23
24
    public function __construct()
25
    {
26
        $this->setEmpty();
27
    }
28
29
    public function is($status)
30
    {
31
        return $this->status[$status];
32
    }
33
34
    public function setDeleted($bit = true)
35
    {
36
        $this->set('deleted', $bit);
37
        if ($this->is('deleted')) {
38
            $this->setDeleting(false);
39
            $this->setDirty(false);
40
        }
41
    }
42
43
    public function setDeleting($bit = true)
44
    {
45
        $this->set('deleting', $bit);
46
    }
47
48
    public function setNew($bit = true)
49
    {
50
        $this->setLoaded();
51
        $this->set('new', $bit);
52
    }
53
54
    public function setLoaded($bit = true)
55
    {
56
        $this->setEmpty(false);
57
        $this->set('loaded', $bit);
58
    }
59
60
    public function setDirty($bit = true)
61
    {
62
        $this->set('dirty', $bit);
63
    }
64
65
    public function setEmpty($bit = true)
66
    {
67
        $this->set('empty', $bit);
68
    }
69
70
    protected function set($key, $bit)
71
    {
72
        $this->status[$key] = (Boolean) $bit;
73
    }
74
}
75