Completed
Pull Request — master (#21)
by De Cramer
02:11
created

Group::getLogins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace eXpansion\Core\Model\UserGroups;
4
5
/**
6
 * A Group of users. Each group of users should have a plugin to handle unser disconnects at the very least.
7
 *
8
 * @package eXpansion\Core\Model\UserGroups
9
 * @author Oliver de Cramer
10
 */
11
class Group
12
{
13
    /** @var string[] */
14
    protected $logins = [];
15
16
    /** @var bool Should the group destroy itself when empty. */
17
    protected $persistent = false;
18
19
    /** @var string The name of the group. */
20
    protected $name;
21
22
    /**
23
     * Group constructor.
24
     *
25
     * @param string $name
26
     */
27 6
    public function __construct($name = null)
28
    {
29 6
        if (is_null($name)) {
30 1
            $this->name = spl_object_hash($this);
31 1
            $this->persistent = false;
32
        } else {
33 5
            $this->name = $name;
34 5
            $this->persistent = true;
35
        }
36 6
    }
37
38
    /**
39
     * Add user to the group.
40
     *
41
     * @param string $login
42
     */
43 5
    public function addLogin($login)
44
    {
45 5
        $this->logins[$login] = true;
46 5
    }
47
48
    /**
49
     * Remove user from the group.
50
     *
51
     * @param $login
52
     */
53 3
    public function removeLogin($login)
54
    {
55 3
        if (isset($this->logins[$login])) {
56 3
            unset($this->logins[$login]);
57
        }
58 3
    }
59
60
    /**
61
     * @return string
62
     */
63 1
    public function getName()
64
    {
65 1
        return $this->name;
66
    }
67
68
    /**
69
     * @return boolean
70
     */
71 2
    public function isPersistent()
72
    {
73 2
        return $this->persistent;
74
    }
75
76
    /**
77
     * Get list of all logins in the group.
78
     *
79
     * @return string[]
80
     */
81 5
    public function getLogins()
82
    {
83 5
        return array_keys($this->logins);
84
    }
85
86
    /**
87
     * Check if user is in the group.
88
     *
89
     * @param string $login
90
     *
91
     * @return bool
92
     */
93 1
    public function hasLogin($login)
94
    {
95 1
        return isset($this->logins[$login]);
96
    }
97
}