Passed
Push — master ( a1b33e...10aa7b )
by Daimona
01:45
created

User::getGroups()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Wiki;
4
5
use BotRiconferme\Wiki\Page\PageBotList;
6
7
/**
8
 * Class representing a single user.
9
 */
10
class User {
11
	/** @var string */
12
	private $name;
13
	/** @var string[] */
14
	private $groups;
15
16
	/**
17
	 * @param string $name
18
	 */
19
	public function __construct( string $name ) {
20
		$this->name = $name;
21
	}
22
23
	/**
24
	 * @return string
25
	 */
26
	public function getName() : string {
27
		return $this->name;
28
	}
29
30
	/**
31
	 * @return string[]
32
	 */
33
	public function getGroups() : array {
34
		if ( $this->groups === null ) {
35
			$usersList = PageBotList::get()->getAdminsList();
36
			$this->groups = array_keys( $usersList[ $this->name ] );
37
		}
38
		return $this->groups;
39
	}
40
41
	/**
42
	 * Whether the user is in the given group
43
	 *
44
	 * @param string $groupName
45
	 * @return bool
46
	 */
47
	public function inGroup( string $groupName ) : bool {
48
		return in_array( $groupName, $this->getGroups() );
49
	}
50
51
	/**
52
	 * @return string
53
	 */
54
	public function __toString() {
55
		return $this->name;
56
	}
57
}
58