Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
User
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
11 / 11
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
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
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 $created;
17    public readonly string $changed;
18    public readonly ?string $deleted;
19    public readonly ?string $expires;
20
21    public function __construct(
22        protected readonly array $data,
23    ) {
24        $this->id = $data['usr'];
25        $this->uid = $data['uid'];
26        $this->username = $data['username'] ?? '';
27        $this->email = $data['email'];
28        $this->password = $data['password'];
29        $this->role = $data['role'];
30        $this->active = $data['active'];
31        $this->created = $data['created'];
32        $this->changed = $data['changed'];
33        $this->deleted = $data['deleted'];
34        $this->expires = $data['expires'] ?? null;
35    }
36
37    public function hasPermission(string $permission): bool
38    {
39        $permissions = new Permissions();
40
41        return $permissions->has($this->role, $permission);
42    }
43
44    public function permissions(): array
45    {
46        $permissions = new Permissions();
47
48        return $permissions->get($this->role);
49    }
50
51    public function array(): array
52    {
53        $data = $this->data;
54        unset($data['password']);
55
56        return $data;
57    }
58}