Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslationQuery
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 13
182
0.00% covered (danger)
0.00%
0 / 1
 factory
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 postWithData
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 queryParameters
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 queryHeaders
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 timeout
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 attachProcessingInstructions
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getTimeout
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUrl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMethod
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryParameters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getBody
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getHeaders
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getProcessingInstructions
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\WebService;
5
6/**
7 * Mutable objects that represents an HTTP(S) query.
8 * NB: Too lazy to make TranslationQueryFactory to make this class immutable.
9 * @author Niklas Laxström
10 * @license GPL-2.0-or-later
11 * @since 2015.02
12 */
13class TranslationQuery {
14    private string $url;
15    private float $timeout = 0;
16    private string $method = 'GET';
17    private array $params = [];
18    private ?string $body = null;
19    private array $headers = [];
20    /** @var mixed Arbitrary data that is returned with TranslationQueryResponse */
21    private $instructions;
22
23    public static function factory( string $url ): TranslationQuery {
24        $obj = new self();
25        $obj->url = $url;
26        return $obj;
27    }
28
29    /** Make this a POST request with given data. */
30    public function postWithData( string $data ): TranslationQuery {
31        $this->method = 'POST';
32        $this->body = $data;
33        return $this;
34    }
35
36    public function queryParameters( array $params ): TranslationQuery {
37        $this->params = $params;
38        return $this;
39    }
40
41    public function queryHeaders( array $headers ): TranslationQuery {
42        $this->headers = $headers;
43        return $this;
44    }
45
46    public function timeout( float $timeout ): TranslationQuery {
47        $this->timeout = $timeout;
48        return $this;
49    }
50
51    /**
52     * Attach arbitrary data that is necessary to process the results.
53     * @param mixed $data
54     * @since 2017.04
55     */
56    public function attachProcessingInstructions( $data ): TranslationQuery {
57        $this->instructions = $data;
58        return $this;
59    }
60
61    public function getTimeout(): float {
62        return $this->timeout;
63    }
64
65    public function getUrl(): string {
66        return $this->url;
67    }
68
69    public function getMethod(): string {
70        return $this->method;
71    }
72
73    public function getQueryParameters(): array {
74        return $this->params;
75    }
76
77    public function getBody(): ?string {
78        return $this->body;
79    }
80
81    public function getHeaders(): array {
82        return $this->headers;
83    }
84
85    /**
86     * Get previously attached result processing instructions.
87     * @return mixed
88     * @since 2017.04
89     */
90    public function getProcessingInstructions() {
91        return $this->instructions;
92    }
93}