Completed
Branch feature/currentUserRefactoring (c13c1d)
by Schlaefer
09:08
created

Owner::__construct()   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
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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\Allowance;
14
15
use Saito\User\ForumsUserInterface;
16
17
class Owner
18
{
19
    /** @var string $resource */
20
    protected $resource;
21
22
    /**
23
     * Constructor
24
     *
25
     * @param string $resource What is granted permission to
26
     */
27
    public function __construct(string $resource)
28
    {
29
        $this->resource = $resource;
30
    }
31
32
    /**
33
     * Check if allowed i.e. user matches.
34
     *
35
     * @param string $resource Resource to check
36
     * @param ForumsUserInterface $CurrentUser CurrentUser
37
     * @param ForumsUserInterface $user Owner of the resource
38
     * @return bool
39
     */
40
    public function check(string $resource, ForumsUserInterface $CurrentUser, ForumsUserInterface $user): bool
41
    {
42
        if ($this->resource !== $resource) {
43
            return false;
44
        }
45
46
        return $CurrentUser->isUser($user);
47
    }
48
}
49