UsageException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 62
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getApiCode() 0 3 1
A getApiResult() 0 3 1
A getRawMessage() 0 3 1
1
<?php
2
3
namespace Mediawiki\Api;
4
5
use Exception;
6
7
/**
8
 * Class representing a Mediawiki Api UsageException
9
 *
10
 * @since 0.1
11
 *
12
 * @author Addshore
13
 */
14
class UsageException extends Exception {
15
16
	/**
17
	 * @var string
18
	 */
19
	private $apiCode;
20
21
	/**
22
	 * @var array
23
	 */
24
	private $result;
25
26
	/**
27
	 * @var string
28
	 */
29
	private $rawMessage;
30
31
	/**
32
	 * @since 0.1
33
	 *
34
	 * @param string $apiCode The API error code.
35
	 * @param string $message The API error message.
36
	 * @param array $result the result the exception was generated from
37
	 */
38 2
	public function __construct( $apiCode = '', $message = '', $result = [] ) {
39 2
		$this->apiCode = $apiCode;
40 2
		$this->result = $result;
41 2
		$this->rawMessage = $message;
42 2
		$message = 'Code: ' . $apiCode . PHP_EOL .
43 2
			'Message: ' . $message . PHP_EOL .
44 2
			'Result: ' . json_encode( $result );
45 2
		parent::__construct( $message, 0, null );
46 2
	}
47
48
	/**
49
	 * @since 0.1
50
	 *
51
	 * @return string
52
	 */
53 2
	public function getApiCode() {
54 2
		return $this->apiCode;
55
	}
56
57
	/**
58
	 * @since 0.3
59
	 *
60
	 * @return array
61
	 */
62 2
	public function getApiResult() {
63 2
		return $this->result;
64
	}
65
66
	/**
67
	 * @since 2.3.0
68
	 *
69
	 * @return string
70
	 */
71
	public function getRawMessage() {
72
		return $this->rawMessage;
73
	}
74
75
}
76