State::setDeleting()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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