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

Force::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
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
/**
16
 * Force allowance
17
 */
18
class Force
19
{
20
    /** @var string $resource */
21
    protected $resource;
22
23
    /** @var bool $allowed */
24
    protected $allowed;
25
26
    /**
27
     * Constructor
28
     *
29
     * @param string $resource What is granted permission to
30
     * @param bool $allowed True or false
31
     */
32
    public function __construct(string $resource, bool $allowed = true)
33
    {
34
        $this->resource = $resource;
35
        $this->allowed = $allowed;
36
    }
37
38
    /**
39
     * Check if allowed i.e. user matches.
40
     *
41
     * @param string $resource Resource to check
42
     * @return bool
43
     */
44
    public function check(string $resource): bool
45
    {
46
        if ($this->resource !== $resource) {
47
            return false;
48
        }
49
50
        return $this->allowed;
51
    }
52
}
53