Completed
Push — master ( 7d085e...e849bf )
by Schlaefer
15:17 queued 07:36
created

ForumsUserTrait::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
nc 1
nop 0
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;
14
15
use Saito\App\Registry;
16
use Saito\User\ForumsUserInterface;
17
use Saito\User\Permission\ResourceAI;
18
19
/**
20
 * Implements ForumsUserInterface
21
 */
22
trait ForumsUserTrait
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getId(): int
28
    {
29
        return (int)$this->get('id');
0 ignored issues
show
Bug introduced by
The method get() does not exist on Saito\User\ForumsUserTrait. Did you maybe mean getId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        return (int)$this->/** @scrutinizer ignore-call */ get('id');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function isUser(ForumsUserInterface $user): bool
36
    {
37
        return $user->getId() === $this->getId();
38
    }
39
40
    /**
41
     * Checks if user is forbidden.
42
     *
43
     * @return bool
44
     */
45
    public function isLocked(): bool
46
    {
47
        return (bool)$this->get('user_lock');
48
    }
49
50
    /**
51
     * Checks if user is forbidden.
52
     *
53
     * @return bool
54
     */
55
    public function isActivated(): bool
56
    {
57
        return !$this->get('activate_code');
58
    }
59
60
    /**
61
     * Get role.
62
     *
63
     * @return string
64
     */
65
    public function getRole(): string
66
    {
67
        return $this->get('user_type');
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    public function numberOfPostings(): int
74
    {
75
        return $this->get('entry_count');
76
    }
77
78
    /**
79
     * {@inheritDoc}
80
     */
81
    public function permission(string $resource, ResourceAI $identity = null): bool
82
    {
83
        if ($identity === null) {
84
            $identity = new ResourceAI();
85
        }
86
87
        $permissions = Registry::get('Permissions');
88
89
        return $permissions->check($resource, $identity->asUser($this));
0 ignored issues
show
Bug introduced by
$this of type Saito\User\ForumsUserTrait is incompatible with the type Saito\User\ForumsUserInterface expected by parameter $user of Saito\User\Permission\ResourceAI::asUser(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
        return $permissions->check($resource, $identity->asUser(/** @scrutinizer ignore-type */ $this));
Loading history...
90
    }
91
}
92