Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.10% covered (success)
93.10%
27 / 29
81.82% covered (warning)
81.82%
9 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
RequestData
93.10% covered (success)
93.10%
27 / 29
81.82% covered (warning)
81.82%
9 / 11
14.06
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
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
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    private $method;
16
17    /** @var UriInterface */
18    private $uri;
19
20    private $protocolVersion;
21
22    /** @var StreamInterface */
23    private $body;
24
25    private $serverParams;
26
27    private $cookieParams;
28
29    private $queryParams;
30
31    /** @var UploadedFileInterface[] */
32    private $uploadedFiles;
33
34    private $postParams;
35
36    /**
37     * Construct a RequestData from an array of parameters.
38     *
39     * @param array $params An associative array of parameters. All parameters
40     *   have defaults. Parameters are:
41     *     - method: The HTTP method
42     *     - uri: The URI
43     *     - protocolVersion: The HTTP protocol version number
44     *     - bodyContents: A string giving the request body
45     *     - serverParams: Equivalent to $_SERVER
46     *     - cookieParams: Equivalent to $_COOKIE
47     *     - queryParams: Equivalent to $_GET
48     *     - uploadedFiles: An array of objects implementing UploadedFileInterface
49     *     - postParams: Equivalent to $_POST
50     *     - pathParams: The path template parameters
51     *     - headers: An array with the key being the header name
52     *     - cookiePrefix: A prefix to add to cookie names in getCookie()
53     */
54    public function __construct( $params = [] ) {
55        $this->method = $params['method'] ?? 'GET';
56        $this->uri = $params['uri'] ?? new Uri;
57        $this->protocolVersion = $params['protocolVersion'] ?? '1.1';
58        $this->body = new StringStream( $params['bodyContents'] ?? '' );
59        $this->serverParams = $params['serverParams'] ?? [];
60        $this->cookieParams = $params['cookieParams'] ?? [];
61        $this->queryParams = $params['queryParams'] ?? [];
62        $this->uploadedFiles = $params['uploadedFiles'] ?? [];
63        $this->postParams = $params['postParams'] ?? [];
64        $this->setPathParams( $params['pathParams'] ?? [] );
65        $this->setHeaders( $params['headers'] ?? [] );
66        $this->setParsedBody( $params['parsedBody'] ?? null );
67        parent::__construct( $params['cookiePrefix'] ?? '' );
68    }
69
70    public function getMethod() {
71        return $this->method;
72    }
73
74    public function getUri() {
75        return $this->uri;
76    }
77
78    public function getProtocolVersion() {
79        return $this->protocolVersion;
80    }
81
82    public function getBody() {
83        return $this->body;
84    }
85
86    public function getServerParams() {
87        return $this->serverParams;
88    }
89
90    public function getCookieParams() {
91        return $this->cookieParams;
92    }
93
94    public function getQueryParams() {
95        return $this->queryParams;
96    }
97
98    public function getUploadedFiles() {
99        return $this->uploadedFiles;
100    }
101
102    public function getPostParams() {
103        return $this->postParams;
104    }
105
106    public function hasBody(): bool {
107        if ( parent::hasBody() ) {
108            return true;
109        }
110
111        if ( $this->parsedBody !== null ) {
112            return true;
113        }
114
115        if ( $this->getBody()->getSize() > 0 ) {
116            return true;
117        }
118
119        return false;
120    }
121
122}