Completed
Push — ciEnhancements ( 259e21...456a90 )
by adam
10:44 queued 08:54
created

ApiUser::getUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Mediawiki\Api;
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
35
	 * @param string $password
36
	 * @param string|null $domain
37
	 *
38
	 * @throws \InvalidArgumentException
39
	 */
40 10
	public function __construct( $username, $password, $domain = null ) {
41 10
		if( !is_string( $username ) || !is_string( $password ) || !( is_null( $domain ) || is_string( $domain ) ) ) {
42 5
			throw new InvalidArgumentException( 'Username, Password and Domain must all be strings' );
43
		}
44 5
		if( empty( $username ) || empty( $password ) ) {
45 3
			throw new InvalidArgumentException( 'Username and Password are not allowed to be empty' );
46
		}
47 2
		$this->username = $username;
48 2
		$this->password = $password;
49 2
		$this->domain   = $domain;
50 2
	}
51
52
	/**
53
	 * @since 0.1
54
	 * @return string
55
	 */
56 8
	public function getUsername() {
57 8
		return $this->username;
58
	}
59
60
	/**
61
	 * @since 0.1
62
	 * @return string
63
	 */
64 6
	public function getPassword() {
65 6
		return $this->password;
66
	}
67
68
	/**
69
	 * @since 0.1
70
	 * @return string
71
	 */
72 4
	public function getDomain() {
73 4
		return $this->domain;
74
	}
75
76
	/**
77
	 * @since 0.1
78
	 * @param mixed $other
79
	 *
80
	 * @return bool
81
	 */
82 6
	public function equals( $other ) {
83
		return $other instanceof self
84 6
			&& $this->username == $other->getUsername()
85 6
			&& $this->password == $other->getPassword()
86 6
			&& $this->domain == $other->getDomain();
87
	}
88
89
} 
90