UserRole::role()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\User\Domain\Model;
14
15
use BenGorUser\User\Domain\Model\Exception\UserRoleInvalidException;
16
17
/**
18
 * User role domain class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
final class UserRole
23
{
24
    /**
25
     * The role in plain string.
26
     *
27
     * @var string
28
     */
29
    private $role;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param string $aRole A role in primitive string
35
     *
36
     * @throws UserRoleInvalidException when the role is not a string
37
     */
38
    public function __construct($aRole)
39
    {
40
        if (!is_string($aRole)) {
41
            throw new UserRoleInvalidException();
42
        }
43
        $this->role = $aRole;
44
    }
45
46
    /**
47
     * Gets the role.
48
     *
49
     * @return string
50
     */
51
    public function role()
52
    {
53
        return $this->role;
54
    }
55
56
    /**
57
     * Method that checks if the user role given is equal to the current.
58
     *
59
     * @param UserRole $aRole The user role
60
     *
61
     * @return bool
62
     */
63
    public function equals(UserRole $aRole)
64
    {
65
        return strtolower($this->role) === strtolower($aRole->role());
66
    }
67
68
    /**
69
     * Magic method that represents the user role in string format.
70
     *
71
     * @return string
72
     */
73
    public function __toString()
74
    {
75
        return $this->role;
76
    }
77
}
78