Completed
Push — master ( 50ff7f...bde7ba )
by Mathieu
03:07
created

Permission::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Charcoal\User\Acl;
4
5
use InvalidArgumentException;
6
7
// Module `charcoal-core` dependencies
8
use Charcoal\Model\AbstractModel;
9
10
// Module `charcoal-base` dependencies
11
use Charcoal\Object\CategorizableInterface;
12
use Charcoal\Object\CategorizableTrait;
13
14
// Module `charcoal-translation` dependencies
15
use Charcoal\Translation\TranslationString;
16
17
/**
18
 * A permission is a simple string, that can be read with additional data (name + category) from storage.
19
 */
20
class Permission extends AbstractModel implements CategorizableInterface
21
{
22
    use CategorizableTrait;
23
24
    /**
25
     * @var string $ident
26
     */
27
    private $ident;
28
29
    /**
30
     * @var TranslationString $name
31
     */
32
    private $name;
33
34
    /**
35
     * Permission can be used as a string (ident).
36
     *
37
     * @return string
38
     */
39
    public function __toString()
40
    {
41
        return (string)$this->ident;
42
    }
43
44
    /**
45
     * @param string $ident The permission identifier.
46
     * @throws InvalidArgumentException If the ident is not a string.
47
     * @return Permission Chainable
48
     */
49
    public function setIdent($ident)
50
    {
51
        if (!is_string($ident)) {
52
            throw new InvalidArgumentException(
53
                'Permission ident needs to be a string'
54
            );
55
        }
56
        $this->ident = $ident;
57
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function ident()
64
    {
65
        return $this->ident;
66
    }
67
68
    /**
69
     * @param mixed $name The permission name / label.
70
     * @return Permission Chainable
71
     */
72
    public function setName($name)
73
    {
74
        $this->name = new TranslationString($name);
75
        return $this;
76
    }
77
78
    /**
79
     * @return TranslationString
80
     */
81
    public function name()
82
    {
83
        return $this->name;
84
    }
85
}
86