@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | $psr17_factory = new Psr17Factory(); |
| 55 | 55 | |
| 56 | - return ( new ServerRequestCreator( |
|
| 56 | + return (new ServerRequestCreator( |
|
| 57 | 57 | $psr17_factory, |
| 58 | 58 | $psr17_factory, |
| 59 | 59 | $psr17_factory, |
| 60 | 60 | $psr17_factory |
| 61 | - ) )->fromGlobals() |
|
| 62 | - ->withBody( $this->stream_from_scalar( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 61 | + ))->fromGlobals() |
|
| 62 | + ->withBody($this->stream_from_scalar($_POST)); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $body = null, |
| 80 | 80 | string $version = '1.1' |
| 81 | 81 | ): RequestInterface { |
| 82 | - return new Request( $method, $uri, $headers, $body, $version ); |
|
| 82 | + return new Request($method, $uri, $headers, $body, $version); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -100,12 +100,12 @@ discard block |
||
| 100 | 100 | string $reason = null |
| 101 | 101 | ): ResponseInterface { |
| 102 | 102 | // Json Encode if body is array or object. |
| 103 | - if ( is_array( $body ) || is_object( $body ) ) { |
|
| 104 | - $body = wp_json_encode( $body ); |
|
| 103 | + if (is_array($body) || is_object($body)) { |
|
| 104 | + $body = wp_json_encode($body); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // If body is false, pass as null. @phpstan |
| 108 | - return new Response( $status, $headers, $body ?: null, $version, $reason ); |
|
| 108 | + return new Response($status, $headers, $body ?: null, $version, $reason); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | int $status = 200, |
| 122 | 122 | array $headers = array() |
| 123 | 123 | ): WP_HTTP_Response { |
| 124 | - return new WP_HTTP_Response( $data, $status, $headers ); |
|
| 124 | + return new WP_HTTP_Response($data, $status, $headers); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -131,19 +131,19 @@ discard block |
||
| 131 | 131 | * @return void |
| 132 | 132 | * @throws InvalidArgumentException |
| 133 | 133 | */ |
| 134 | - public function emit_response( $response ): void { |
|
| 134 | + public function emit_response($response): void { |
|
| 135 | 135 | |
| 136 | 136 | // Throw if not a valid response. |
| 137 | 137 | if ( ! $response instanceof ResponseInterface |
| 138 | - && ! $response instanceof WP_HTTP_Response ) { |
|
| 139 | - throw new InvalidArgumentException( 'Only ResponseInterface & WP_REST_Response responses can be emitted.' ); |
|
| 138 | + && ! $response instanceof WP_HTTP_Response) { |
|
| 139 | + throw new InvalidArgumentException('Only ResponseInterface & WP_REST_Response responses can be emitted.'); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Based on type, emit the response. |
| 143 | - if ( $response instanceof ResponseInterface ) { |
|
| 144 | - $this->emit_psr7_response( $response ); |
|
| 143 | + if ($response instanceof ResponseInterface) { |
|
| 144 | + $this->emit_psr7_response($response); |
|
| 145 | 145 | } else { |
| 146 | - $this->emit_wp_response( $response ); |
|
| 146 | + $this->emit_wp_response($response); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param ResponseInterface $response |
| 154 | 154 | * @return void |
| 155 | 155 | */ |
| 156 | - public function emit_psr7_response( ResponseInterface $response ): void { |
|
| 156 | + public function emit_psr7_response(ResponseInterface $response): void { |
|
| 157 | 157 | |
| 158 | 158 | // If headers sent, throw headers already sent. |
| 159 | 159 | $this->headers_sent(); |
@@ -165,19 +165,19 @@ discard block |
||
| 165 | 165 | $response->getStatusCode(), |
| 166 | 166 | $response->getReasonPhrase() |
| 167 | 167 | ); |
| 168 | - header( $status_line, true ); |
|
| 168 | + header($status_line, true); |
|
| 169 | 169 | |
| 170 | 170 | // Append headers. |
| 171 | - foreach ( $this->headers_with_json( $response->getHeaders() ) |
|
| 172 | - as $name => $values ) { |
|
| 171 | + foreach ($this->headers_with_json($response->getHeaders()) |
|
| 172 | + as $name => $values) { |
|
| 173 | 173 | |
| 174 | 174 | // If values are an array, join. |
| 175 | - $values = is_array( $values ) |
|
| 176 | - ? join( ',', $values ) |
|
| 175 | + $values = is_array($values) |
|
| 176 | + ? join(',', $values) |
|
| 177 | 177 | : (string) $values; |
| 178 | 178 | |
| 179 | - $response_header = sprintf( '%s: %s', $name, $values ); |
|
| 180 | - header( $response_header, false ); |
|
| 179 | + $response_header = sprintf('%s: %s', $name, $values); |
|
| 180 | + header($response_header, false); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Emit body. |
@@ -191,28 +191,28 @@ discard block |
||
| 191 | 191 | * @param WP_HTTP_Response $response |
| 192 | 192 | * @return void |
| 193 | 193 | */ |
| 194 | - public function emit_wp_response( WP_HTTP_Response $response ): void { |
|
| 194 | + public function emit_wp_response(WP_HTTP_Response $response): void { |
|
| 195 | 195 | |
| 196 | 196 | // If headers sent, throw headers already sent. |
| 197 | 197 | $this->headers_sent(); |
| 198 | 198 | |
| 199 | 199 | // Append headers. |
| 200 | - foreach ( $this->headers_with_json( $response->get_headers() ) |
|
| 201 | - as $name => $values ) { |
|
| 200 | + foreach ($this->headers_with_json($response->get_headers()) |
|
| 201 | + as $name => $values) { |
|
| 202 | 202 | |
| 203 | - $values = is_array( $values ) |
|
| 204 | - ? join( ',', $values ) |
|
| 203 | + $values = is_array($values) |
|
| 204 | + ? join(',', $values) |
|
| 205 | 205 | : (string) $values; |
| 206 | 206 | |
| 207 | - $header = sprintf( '%s: %s', $name, $values ); |
|
| 207 | + $header = sprintf('%s: %s', $name, $values); |
|
| 208 | 208 | |
| 209 | 209 | // Set the headers. |
| 210 | - header( $header, false ); |
|
| 210 | + header($header, false); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // Emit body. |
| 214 | 214 | $body = $response->get_data(); |
| 215 | - print is_string( $body ) ? $body : wp_json_encode( $body ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 215 | + print is_string($body) ? $body : wp_json_encode($body); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 216 | 216 | return; // phpcs:ignore Squiz.PHP.NonExecutableCode.ReturnNotRequired |
| 217 | 217 | } |
| 218 | 218 | |
@@ -222,9 +222,9 @@ discard block |
||
| 222 | 222 | * @param array<string, mixed> $headers |
| 223 | 223 | * @return array<string, mixed> |
| 224 | 224 | */ |
| 225 | - public function headers_with_json( array $headers = array() ): array { |
|
| 226 | - if ( ! array_key_exists( 'Content-Type', $headers ) ) { |
|
| 227 | - $headers['Content-Type'] = 'application/json; charset=' . get_option( 'blog_charset' ); |
|
| 225 | + public function headers_with_json(array $headers = array()): array { |
|
| 226 | + if ( ! array_key_exists('Content-Type', $headers)) { |
|
| 227 | + $headers['Content-Type'] = 'application/json; charset=' . get_option('blog_charset'); |
|
| 228 | 228 | } |
| 229 | 229 | return $headers; |
| 230 | 230 | } |
@@ -236,8 +236,8 @@ discard block |
||
| 236 | 236 | * @throws RuntimeException |
| 237 | 237 | */ |
| 238 | 238 | protected function headers_sent(): void { |
| 239 | - if ( headers_sent() ) { |
|
| 240 | - throw new RuntimeException( 'Headers were already sent. The response could not be emitted!' ); |
|
| 239 | + if (headers_sent()) { |
|
| 240 | + throw new RuntimeException('Headers were already sent. The response could not be emitted!'); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @param string|int|float|object|array<mixed> $data |
| 248 | 248 | * @return \Psr\Http\Message\StreamInterface |
| 249 | 249 | */ |
| 250 | - public function stream_from_scalar( $data ): StreamInterface { |
|
| 251 | - return Stream::create( json_encode( $data ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
| 250 | + public function stream_from_scalar($data): StreamInterface { |
|
| 251 | + return Stream::create(json_encode($data) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
| 252 | 252 | } |
| 253 | 253 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @return HTTP |
| 51 | 51 | */ |
| 52 | 52 | public static function get_http(): HTTP { |
| 53 | - if ( ! static::$http ) { |
|
| 53 | + if ( ! static::$http) { |
|
| 54 | 54 | static::$http = new HTTP(); |
| 55 | 55 | } |
| 56 | 56 | return static::$http; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | string $version = '1.1' |
| 85 | 85 | ): RequestInterface { |
| 86 | 86 | return static::get_http() |
| 87 | - ->psr7_request( $method, $uri, $headers, $body, $version ); |
|
| 87 | + ->psr7_request($method, $uri, $headers, $body, $version); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | string $reason = null |
| 106 | 106 | ): ResponseInterface { |
| 107 | 107 | return static::get_http() |
| 108 | - ->psr7_response( $body, $status, $headers, $version, $reason ); |
|
| 108 | + ->psr7_response($body, $status, $headers, $version, $reason); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | array $headers = array() |
| 123 | 123 | ): WP_HTTP_Response { |
| 124 | 124 | return static::get_http() |
| 125 | - ->wp_response( $data, $status, $headers ); |
|
| 125 | + ->wp_response($data, $status, $headers); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @param string|int|float|object|array<mixed> $value |
| 132 | 132 | * @return StreamInterface |
| 133 | 133 | */ |
| 134 | - public static function stream_from_scalar( $value ): StreamInterface { |
|
| 135 | - return Stream::create( json_encode( $value ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
| 134 | + public static function stream_from_scalar($value): StreamInterface { |
|
| 135 | + return Stream::create(json_encode($value) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode |
|
| 136 | 136 | } |
| 137 | 137 | } |