Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
84.21% covered (warning)
84.21%
16 / 19
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
User
84.21% covered (warning)
84.21%
16 / 19
75.00% covered (warning)
75.00%
3 / 4
4.06
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 hasPermission
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 permissions
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 array
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray;
6
7class User
8{
9    public readonly int $id;
10    public readonly string $uid;
11    public readonly string $username;
12    public readonly string $email;
13    public readonly string $password;
14    public readonly string $role;
15    public readonly bool $active;
16    public readonly ?string $panelLocale;
17    public readonly string $created;
18    public readonly string $changed;
19    public readonly ?string $deleted;
20    public readonly ?string $expires;
21
22    public function __construct(
23        protected readonly array $data,
24    ) {
25        $this->id = $data['usr'];
26        $this->uid = $data['uid'];
27        $this->username = $data['username'] ?? '';
28        $this->email = $data['email'];
29        $this->password = $data['password'];
30        $this->role = $data['role'];
31        $this->active = $data['active'];
32        $this->panelLocale = $data['panel_locale'] ?? null;
33        $this->created = $data['created'];
34        $this->changed = $data['changed'];
35        $this->deleted = $data['deleted'];
36        $this->expires = $data['expires'] ?? null;
37    }
38
39    public function hasPermission(string $permission): bool
40    {
41        $permissions = new Permissions();
42
43        return $permissions->has($this->role, $permission);
44    }
45
46    public function permissions(): array
47    {
48        $permissions = new Permissions();
49
50        return $permissions->get($this->role);
51    }
52
53    public function array(): array
54    {
55        $data = $this->data;
56        unset($data['password']);
57
58        return $data;
59    }
60}