Completed
Branch release/5.5.0 (ca3c12)
by Schlaefer
09:46
created

ResourceAI::getRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Saito\User\Permission;
14
15
use Saito\User\ForumsUserInterface;
16
17
/**
18
 * Resource Access Identity
19
 */
20
class ResourceAI
21
{
22
    /** @var string role */
23
    protected $role = null;
24
25
    /** @var int user-ID */
26
    protected $userId = null;
27
28
    /** @var ForumsUserInterface User to check against */
29
    protected $user = null;
30
31
    /**
32
     * Get the user which requests the permission
33
     *
34
     * @return ForumsUserInterface|null
35
     */
36
    public function getUser(): ?ForumsUserInterface
37
    {
38
        return $this->user;
39
    }
40
41
    /**
42
     * Get owner-ID of the resource
43
     *
44
     * @return int|null
45
     */
46
    public function getOwner(): ?int
47
    {
48
        return $this->userId;
49
    }
50
51
    /**
52
     * Get owner of the resource
53
     *
54
     * @return string|null
55
     */
56
    public function getRole(): ?string
57
    {
58
        return $this->role;
59
    }
60
61
    /**
62
     * Set a user which requests the permission
63
     *
64
     * @param ForumsUserInterface $user The user.
65
     * @return self
66
     */
67
    public function asUser(ForumsUserInterface $user): self
68
    {
69
        $this->user = $user;
70
71
        return $this;
72
    }
73
74
    /**
75
     * Set owner role
76
     *
77
     * @param string $role Owner's role
78
     * @return self
79
     */
80
    public function onRole(string $role): self
81
    {
82
        $this->role = $role;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Set owner identity
89
     *
90
     * @param int $userId Owner's user-ID
91
     * @return self
92
     */
93
    public function onOwner(int $userId): self
94
    {
95
        $this->userId = $userId;
96
97
        return $this;
98
    }
99
}
100