Permission::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Omatech\Mage\Core\Domains\Permissions;
4
5
use Omatech\Mage\Core\Domains\Permissions\Contracts\AllPermissionInterface;
6
use Omatech\Mage\Core\Domains\Permissions\Contracts\FindPermissionInterface;
7
use Omatech\Mage\Core\Domains\Permissions\Contracts\PermissionInterface;
8
use Omatech\Mage\Core\Domains\Permissions\Features\ExistsAndDeletePermission;
9
use Omatech\Mage\Core\Domains\Permissions\Features\FindOrFailPermission;
10
use Omatech\Mage\Core\Domains\Permissions\Features\UpdateOrCreatePermission;
11
use Omatech\Mage\Core\Domains\Shared\Traits\FromArray;
12
13
class Permission implements PermissionInterface
14
{
15
    use FromArray;
16
17
    private $id;
18
    private $name;
19
    private $guardName;
20
    private $createdAt;
21
    private $updatedAt;
22
23
    /**
24
     * @return int|null
25
     */
26 23
    public function getId(): ?int
27
    {
28 23
        return $this->id;
29
    }
30
31
    /**
32
     * @param int $id
33
     * @return $this
34
     */
35 21
    public function setId(int $id)
36
    {
37 21
        $this->id = $id;
38
39 21
        return $this;
40
    }
41
42
    /**
43
     * @return string
44
     */
45 21
    public function getName(): string
46
    {
47 21
        return $this->name;
48
    }
49
50
    /**
51
     * @param string $name
52
     * @return $this
53
     */
54 23
    public function setName(string $name)
55
    {
56 23
        $this->name = $name;
57
58 23
        return $this;
59
    }
60
61
    /**
62
     * @return string
63
     */
64 21
    public function getGuardName(): string
65
    {
66 21
        return $this->guardName;
67
    }
68
69
    /**
70
     * @param string $guardName
71
     * @return $this
72
     */
73 23
    public function setGuardName(string $guardName)
74
    {
75 23
        $this->guardName = $guardName;
76
77 23
        return $this;
78
    }
79
80
    /**
81
     * @return string
82
     */
83 3
    public function getCreatedAt(): string
84
    {
85 3
        return $this->createdAt;
86
    }
87
88
    /**
89
     * @param string $createdAt
90
     * @return $this
91
     */
92 21
    public function setCreatedAt(string $createdAt)
93
    {
94 21
        $this->createdAt = $createdAt;
95
96 21
        return $this;
97
    }
98
99
    /**
100
     * @return string
101
     */
102 3
    public function getUpdatedAt(): string
103
    {
104 3
        return $this->updatedAt;
105
    }
106
107
    /**
108
     * @param string $updatedAt
109
     * @return $this
110
     */
111 21
    public function setUpdatedAt(string $updatedAt)
112
    {
113 21
        $this->updatedAt = $updatedAt;
114
115 21
        return $this;
116
    }
117
118
    /**
119
     * @param AllPermissionInterface $all
120
     * @return mixed
121
     */
122 1
    public static function all(AllPermissionInterface $all)
123
    {
124 1
        return $all->get();
125
    }
126
127
    /**
128
     * @param FindPermissionInterface $find
129
     * @param array $params
130
     * @return mixed
131
     * @throws Exceptions\PermissionDoesNotExistsException
132
     */
133 4
    public static function find(FindPermissionInterface $find, array $params)
134
    {
135 4
        return (new FindOrFailPermission())->make($find, $params);
136
    }
137
138
    /**
139
     * @return bool
140
     * @throws Exceptions\PermissionAlreadyExistsException
141
     * @throws Exceptions\PermissionDoesNotExistsException
142
     * @throws Exceptions\PermissionNameExistsMustBeUniqueException
143
     */
144 21
    public function save(): bool
145
    {
146 21
        return (new UpdateOrCreatePermission())->make($this);
147
    }
148
149
    /**
150
     * @return bool
151
     * @throws Exceptions\PermissionDoesNotExistsException
152
     * @throws Exceptions\PermissionIsAttachedException
153
     */
154 4
    public function delete(): bool
155
    {
156 4
        return (new ExistsAndDeletePermission())->make($this);
157
    }
158
}
159