Test Failed
Push — master ( d7824a...a03b1d )
by Christian
06:13 queued 18s
created

Role::setUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Omatech\Mage\Core\Domains\Roles;
4
5
use Omatech\Mage\Core\Domains\Roles\Jobs\AllRole;
6
use Omatech\Mage\Core\Domains\Shared\Traits\FromArray;
7
use Omatech\Mage\Core\Domains\Permissions\PermissionModel;
8
use Omatech\Mage\Core\Domains\Roles\Contracts\RoleInterface;
9
use Omatech\Mage\Core\Domains\Roles\Features\FindOrFailRole;
10
use Omatech\Mage\Core\Domains\Roles\Contracts\AllRoleInterface;
11
use Omatech\Mage\Core\Domains\Roles\Features\UpdateOrCreateRole;
12
use Omatech\Mage\Core\Domains\Roles\Features\ExistsAndDeleteRole;
13
use Omatech\Mage\Core\Domains\Permissions\Contracts\PermissionInterface;
14
15
class Role implements RoleInterface
16
{
17
    use FromArray;
18
19
    private $id;
20
    private $name;
21
    private $guardName;
22
    private $createdAt;
23
    private $updatedAt;
24
    private $permissions = [];
25
26
    /**
27
     * @return int|null
28
     */
29 22
    public function getId(): ?int
30
    {
31 22
        return $this->id;
32
    }
33
34
    /**
35
     * @param int $id
36
     * @return Role
37
     */
38 21
    public function setId(int $id): self
39
    {
40 21
        $this->id = $id;
41
42 21
        return $this;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 21
    public function getName(): string
49
    {
50 21
        return $this->name;
51
    }
52
53
    /**
54
     * @param string $name
55
     * @return Role
56
     */
57 23
    public function setName(string $name): self
58
    {
59 23
        $this->name = $name;
60
61 23
        return $this;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 21
    public function getGuardName(): string
68
    {
69 21
        return $this->guardName;
70
    }
71
72
    /**
73
     * @param string $guardName
74
     * @return Role
75
     */
76 23
    public function setGuardName(string $guardName): self
77
    {
78 23
        $this->guardName = $guardName;
79
80 23
        return $this;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 5
    public function getCreatedAt(): string
87
    {
88 5
        return $this->createdAt;
89
    }
90
91
    /**
92
     * @param string $createdAt
93
     * @return Role
94
     */
95 21
    public function setCreatedAt(string $createdAt): self
96
    {
97 21
        $this->createdAt = $createdAt;
98
99 21
        return $this;
100
    }
101
102
    /**
103
     * @return string
104
     */
105 5
    public function getUpdatedAt(): string
106
    {
107 5
        return $this->updatedAt;
108
    }
109
110
    /**
111
     * @param string $updatedAt
112
     * @return Role
113
     */
114 21
    public function setUpdatedAt(string $updatedAt): self
115
    {
116 21
        $this->updatedAt = $updatedAt;
117
118 21
        return $this;
119
    }
120
121
    /**
122
     * @return array
123
     */
124 22
    public function getPermissions(): array
125
    {
126 22
        return $this->permissions;
127
    }
128
129
    /**
130
     * @return array
131
     */
132 21
    public function getPermissionsIds(): array
133
    {
134
        return array_map(static function (PermissionInterface $permission) {
135 7
            return $permission->getId();
136 21
        }, $this->getPermissions());
137
    }
138
139
    /**
140
     * @param AllRoleInterface $all
141
     * @return mixed
142
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
143
     */
144 1
    public static function all(AllRoleInterface $all)
145
    {
146 1
        return app()->make(AllRole::class)->make($all);
147
    }
148
149
    /**
150
     * @param int $id
151
     * @return Role
152
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
153
     */
154 4
    public static function find(int $id): self
155
    {
156 4
        return app()->make(FindOrFailRole::class)->make($id);
157
    }
158
159
    /**
160
     * @return bool
161
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
162
     */
163 21
    public function save(): bool
164
    {
165 21
        return app()->make(UpdateOrCreateRole::class)->make($this);
166
    }
167
168
    /**
169
     * @return bool
170
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
171
     */
172 4
    public function delete(): bool
173
    {
174 4
        return app()->make(ExistsAndDeleteRole::class)->make($this);
175
    }
176
177
    /**
178
     * @param PermissionInterface $permission
179
     * @return Role
180
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
181
     */
182 2
    public function assignPermission(PermissionInterface $permission): self
183
    {
184 2
        $this->permissions = app()->make(PermissionModel::class)
185 2
            ->assignPermission($this->getPermissions(), $permission);
186
187 2
        return $this;
188
    }
189
190
    /**
191
     * @param array $permissions
192
     * @return Role
193
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
194
     */
195 8
    public function assignPermissions(array $permissions): self
196
    {
197 8
        $this->permissions = app()->make(PermissionModel::class)
198 8
            ->assignPermissions($this->getPermissions(), $permissions);
199
200 7
        return $this;
201
    }
202
203
    /**
204
     * @param PermissionInterface $permission
205
     * @return Role
206
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
207
     */
208 1
    public function removePermission(PermissionInterface $permission): self
209
    {
210 1
        $this->permissions = app()->make(PermissionModel::class)
211 1
            ->removePermission($this->getPermissions(), $permission);
212
213 1
        return $this;
214
    }
215
216
    /**
217
     * @param array $permissions
218
     * @return Role
219
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
220
     */
221 2
    public function removePermissions(array $permissions): self
222
    {
223 2
        $this->permissions = app()->make(PermissionModel::class)
224 2
            ->removePermissions($this->getPermissions(), $permissions);
225
226 1
        return $this;
227
    }
228
}
229