Completed
Branch feature/currentUserRefactoring (c13c1d)
by Schlaefer
04:13
created

Owner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A check() 0 8 2
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