Completed
Push — main ( d84a15...26c7b4 )
by
unknown
04:34
created

ApiUser::getDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Addwiki\Mediawiki\Api\Client;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @since 0.1
9
 *
10
 * @author Addshore
11
 * @author RobinR1
12
 * @author Bene
13
 *
14
 * Represents a user that can log in to the api
15
 */
16
class ApiUser {
17
18
	/**
19
	 * @var string
20
	 */
21
	private $password;
22
23
	/**
24
	 * @var string
25
	 */
26
	private $username;
27
28
	/**
29
	 * @var string
30
	 */
31
	private $domain;
32
33
	/**
34
	 * @param string $username The username.
35
	 * @param string $password The user's password.
36
	 * @param string|null $domain The domain (for authentication systems that support domains).
37
	 *
38
	 * @throws InvalidArgumentException
39
	 */
40
	public function __construct( $username, $password, $domain = null ) {
41
		$domainIsStringOrNull = ( is_string( $domain ) || $domain === null );
42
		if ( !is_string( $username ) || !is_string( $password ) || !$domainIsStringOrNull ) {
43
			throw new InvalidArgumentException( 'Username, Password and Domain must all be strings' );
44
		}
45
		if ( empty( $username ) || empty( $password ) ) {
46
			throw new InvalidArgumentException( 'Username and Password are not allowed to be empty' );
47
		}
48
		$this->username = $username;
49
		$this->password = $password;
50
		$this->domain   = $domain;
51
	}
52
53
	/**
54
	 * @since 0.1
55
	 * @return string
56
	 */
57
	public function getUsername() {
58
		return $this->username;
59
	}
60
61
	/**
62
	 * @since 0.1
63
	 * @return string
64
	 */
65
	public function getPassword() {
66
		return $this->password;
67
	}
68
69
	/**
70
	 * @since 0.1
71
	 * @return string
72
	 */
73
	public function getDomain() {
74
		return $this->domain;
75
	}
76
77
	/**
78
	 * @since 0.1
79
	 * @param mixed $other Another ApiUser object to compare with.
80
	 *
81
	 * @return bool
82
	 */
83
	public function equals( $other ) {
84
		return $other instanceof self
85
			&& $this->username === $other->getUsername()
86
			&& $this->password === $other->getPassword()
87
			&& $this->domain === $other->getDomain();
88
	}
89
90
}
91