Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.32% covered (success)
90.32%
28 / 31
72.73% covered (warning)
72.73%
8 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
RequestData
90.32% covered (success)
90.32%
28 / 31
72.73% covered (warning)
72.73%
8 / 11
15.20
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 getMethod
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUri
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getProtocolVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getBody
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getServerParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCookieParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQueryParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUploadedFiles
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getPostParams
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 hasBody
88.89% covered (warning)
88.89%
8 / 9
0.00% covered (danger)
0.00%
0 / 1
5.03
1<?php
2
3namespace MediaWiki\Rest;
4
5use GuzzleHttp\Psr7\Uri;
6use Psr\Http\Message\StreamInterface;
7use Psr\Http\Message\UploadedFileInterface;
8use Psr\Http\Message\UriInterface;
9
10/**
11 * This is a Request class that allows data to be injected, for the purposes
12 * of testing or internal requests.
13 */
14class RequestData extends RequestBase {
15    /** @var string */
16    private $method;
17
18    /** @var UriInterface */
19    private $uri;
20
21    /** @var string */
22    private $protocolVersion;
23
24    /** @var StreamInterface */
25    private $body;
26
27    /** @var array */
28    private $serverParams;
29
30    /** @var array */
31    private $cookieParams;
32
33    /** @var array */
34    private $queryParams;
35
36    /** @var UploadedFileInterface[] */
37    private $uploadedFiles;
38
39    /** @var array */
40    private $postParams;
41
42    /**
43     * Construct a RequestData from an array of parameters.
44     *
45     * @param array $params An associative array of parameters. All parameters
46     *   have defaults. Parameters are:
47     *   - method: The HTTP method
48     *   - uri: The URI
49     *   - protocolVersion: The HTTP protocol version number
50     *   - bodyContents: A string giving the request body
51     *   - serverParams: Equivalent to $_SERVER
52     *   - cookieParams: Equivalent to $_COOKIE
53     *   - queryParams: Equivalent to $_GET
54     *   - uploadedFiles: An array of objects implementing UploadedFileInterface
55     *   - postParams: Equivalent to $_POST
56     *   - pathParams: The path template parameters
57     *   - headers: An array with the key being the header name
58     *   - cookiePrefix: A prefix to add to cookie names in getCookie()
59     */
60    public function __construct( $params = [] ) {
61        $this->method = $params['method'] ?? 'GET';
62        $this->uri = $params['uri'] ?? new Uri;
63        $this->protocolVersion = $params['protocolVersion'] ?? '1.1';
64        $this->body = new StringStream( $params['bodyContents'] ?? '' );
65        $this->serverParams = $params['serverParams'] ?? [];
66        $this->cookieParams = $params['cookieParams'] ?? [];
67        $this->queryParams = $params['queryParams'] ?? [];
68        $this->uploadedFiles = $params['uploadedFiles'] ?? [];
69        $this->postParams = $params['postParams'] ?? [];
70        $this->setPathParams( $params['pathParams'] ?? [] );
71        $this->setHeaders( $params['headers'] ?? [] );
72        $this->setParsedBody( $params['parsedBody'] ?? null );
73        parent::__construct( $params['cookiePrefix'] ?? '' );
74    }
75
76    /** @inheritDoc */
77    public function getMethod() {
78        return $this->method;
79    }
80
81    /** @inheritDoc */
82    public function getUri() {
83        return $this->uri;
84    }
85
86    /** @inheritDoc */
87    public function getProtocolVersion() {
88        return $this->protocolVersion;
89    }
90
91    /** @inheritDoc */
92    public function getBody() {
93        return $this->body;
94    }
95
96    /** @inheritDoc */
97    public function getServerParams() {
98        return $this->serverParams;
99    }
100
101    /** @inheritDoc */
102    public function getCookieParams() {
103        return $this->cookieParams;
104    }
105
106    /** @inheritDoc */
107    public function getQueryParams() {
108        return $this->queryParams;
109    }
110
111    /** @inheritDoc */
112    public function getUploadedFiles() {
113        return $this->uploadedFiles;
114    }
115
116    /** @inheritDoc */
117    public function getPostParams() {
118        return $this->postParams;
119    }
120
121    /** @inheritDoc */
122    public function hasBody(): bool {
123        if ( parent::hasBody() ) {
124            return true;
125        }
126
127        if ( $this->parsedBody !== null ) {
128            return true;
129        }
130
131        if ( $this->postParams !== [] ) {
132            return true;
133        }
134
135        if ( $this->getBody()->getSize() > 0 ) {
136            return true;
137        }
138
139        return false;
140    }
141
142}