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

ForumsUserTrait::isUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
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;
14
15
use Saito\App\Registry;
16
use Saito\User\ForumsUserInterface;
17
use Saito\User\Permission\Identifier\IdentifierInterface;
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
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

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');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
    }
59
60
    /**
61
     * Get role.
62
     *
63
     * @return string
64
     */
65
    public function getRole(): string
66
    {
67
        return $this->get('user_type');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    public function numberOfPostings(): int
74
    {
75
        return $this->get('entry_count');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
76
    }
77
78
    /**
79
     * {@inheritDoc}
80
     */
81
    public function permission(string $resource, IdentifierInterface ...$identifiers): bool
82
    {
83
        $permission = Registry::get('Permissions');
84
85
        return $permission->check($this, $resource, ...$identifiers);
86
    }
87
}
88