UserInfo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getName() 0 2 1
A getAliases() 0 2 1
A getInfo() 0 2 1
A extractGroups() 0 2 1
A extractGroupsWithDates() 0 2 1
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Wiki;
4
5
/**
6
 * Value object containing the data about a User that is stored in the list page
7
 */
8
class UserInfo {
9
	/** @var string */
10
	private $name;
11
	/**
12
	 * @var array
13
	 * @phan-var array<string,string|string[]>
14
	 */
15
	private $info;
16
17
	private const GROUP_KEYS = [ 'sysop', 'bureaucrat', 'checkuser' ];
18
19
	/**
20
	 * @param string $name
21
	 * @param array $info
22
	 * @phan-param array<string,string|string[]> $info
23
	 */
24
	public function __construct( string $name, array $info ) {
25
		$this->name = $name;
26
		$this->info = $info;
27
	}
28
29
	/**
30
	 * @return string
31
	 */
32
	public function getName(): string {
33
		return $this->name;
34
	}
35
36
	/**
37
	 * @return array
38
	 * @phan-return array<string,string|string[]>
39
	 */
40
	public function getInfo(): array {
41
		return $this->info;
42
	}
43
44
	/**
45
	 * @return string[]
46
	 */
47
	public function extractGroups(): array {
48
		return array_keys( $this->extractGroupsWithDates() );
49
	}
50
51
	/**
52
	 * @return string[]
53
	 */
54
	public function extractGroupsWithDates(): array {
55
		return array_intersect_key( $this->getInfo(), array_fill_keys( self::GROUP_KEYS, 1 ) );
56
	}
57
58
	/**
59
	 * @return string[]
60
	 */
61
	public function getAliases(): array {
62
		return $this->getInfo()['aliases'] ?? [];
63
	}
64
}
65