Passed
Push — master ( bac275...6454e3 )
by Daimona
02:17
created

PageBotList   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A get() 0 6 2
A getAdminsList() 0 2 1
A getValidTimestamp() 0 13 4
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Wiki\Page;
4
5
use BotRiconferme\Config;
6
7
/**
8
 * Singleton class representing the JSON list of admins
9
 */
10
class PageBotList extends Page {
11
	/**
12
	 * @private Use self::get()
13
	 */
14
	public function __construct() {
15
		parent::__construct( Config::getInstance()->get( 'list-title' ) );
16
	}
17
18
	/**
19
	 * Instance getter
20
	 *
21
	 * @return self
22
	 */
23
	public static function get() : self {
24
		static $instance = null;
25
		if ( $instance === null ) {
26
			$instance = new self;
27
		}
28
		return $instance;
29
	}
30
31
	/**
32
	 * Get the valid timestamp for the given groups
33
	 *
34
	 * @param array $groups
35
	 * @return int
36
	 */
37
	public static function getValidTimestamp( array $groups ): int {
38
		$checkuser = isset( $groups['checkuser'] ) ?
39
			\DateTime::createFromFormat( 'd/m/Y', $groups['checkuser'] )->getTimestamp() :
40
			0;
41
		$bureaucrat = isset( $groups['bureaucrat'] ) ?
42
			\DateTime::createFromFormat( 'd/m/Y', $groups['bureaucrat'] )->getTimestamp() :
43
			0;
44
45
		$timestamp = max( $bureaucrat, $checkuser );
46
		if ( $timestamp === 0 ) {
47
			$timestamp = \DateTime::createFromFormat( 'd/m/Y', $groups['sysop'] )->getTimestamp();
48
		}
49
		return $timestamp;
50
	}
51
52
	/**
53
	 * Get the actual list of admins
54
	 *
55
	 * @return array[]
56
	 */
57
	public function getAdminsList() : array {
58
		return json_decode( $this->getContent(), true );
59
	}
60
}
61