Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
TranslationQueryResponse | |
0.00% |
0 / 13 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getStatusCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStatusMessage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getQuery | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\WebService; |
5 | |
6 | /** |
7 | * Value object that represents a HTTP(S) query response. |
8 | * @author Niklas Laxström |
9 | * @license GPL-2.0-or-later |
10 | * @since 2015.02 |
11 | */ |
12 | class TranslationQueryResponse { |
13 | private int $code; |
14 | private string $reason; |
15 | private array $headers; |
16 | private ?string $body; |
17 | private string $error; |
18 | /** @var TranslationQuery */ |
19 | private $query; |
20 | |
21 | public function __construct( array $data, TranslationQuery $query ) { |
22 | $response = $data['response']; |
23 | |
24 | $this->code = (int)$response['code']; |
25 | $this->reason = $response['reason']; |
26 | $this->headers = $response['headers']; |
27 | $this->body = $response['body']; |
28 | $this->error = $response['error']; |
29 | $this->query = $query; |
30 | } |
31 | |
32 | public function getStatusCode(): int { |
33 | return $this->code; |
34 | } |
35 | |
36 | public function getStatusMessage(): string { |
37 | if ( $this->code === 0 ) { |
38 | return $this->error; |
39 | } else { |
40 | return $this->reason; |
41 | } |
42 | } |
43 | |
44 | public function getBody(): ?string { |
45 | return $this->body; |
46 | } |
47 | |
48 | /** |
49 | * Get the TranslationQuery that was made for this request. |
50 | * @since 2017.04 |
51 | */ |
52 | public function getQuery(): TranslationQuery { |
53 | return $this->query; |
54 | } |
55 | } |