Passed
Pull Request — master (#12)
by
unknown
02:00
created
src/HTTP.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 
55 55
 		$psr17_factory = new Psr17Factory();
56 56
 
57
-		return ( new ServerRequestCreator(
57
+		return (new ServerRequestCreator(
58 58
 			$psr17_factory,
59 59
 			$psr17_factory,
60 60
 			$psr17_factory,
61 61
 			$psr17_factory
62
-		) )->fromGlobals()
63
-			->withBody( $this->stream_from_scalar( $_POST ) );  // phpcs:ignore WordPress.Security.NonceVerification.Missing
62
+		))->fromGlobals()
63
+			->withBody($this->stream_from_scalar($_POST)); // phpcs:ignore WordPress.Security.NonceVerification.Missing
64 64
 	}
65 65
 
66 66
 	/**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		$body = null,
83 83
 		string $version = '1.1'
84 84
 	): RequestInterface {
85
-		return new Request( $method, $uri, $headers, $body, $version );
85
+		return new Request($method, $uri, $headers, $body, $version);
86 86
 	}
87 87
 
88 88
 	/**
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 		?string $reason = null
105 105
 	): ResponseInterface {
106 106
 		// Json Encode if body is array or object.
107
-		if ( is_array( $body ) || is_object( $body ) ) {
108
-			$body = wp_json_encode( $body );
107
+		if (is_array($body) || is_object($body)) {
108
+			$body = wp_json_encode($body);
109 109
 		}
110 110
 
111 111
 		// If body is false, pass as null. @phpstan
112
-		return new Response( $status, $headers, $body ?: null, $version, $reason );
112
+		return new Response($status, $headers, $body ?: null, $version, $reason);
113 113
 	}
114 114
 
115 115
 	/**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		int $status = 200,
127 127
 		array $headers = array()
128 128
 	): WP_HTTP_Response {
129
-		return new WP_HTTP_Response( $data, $status, $headers );
129
+		return new WP_HTTP_Response($data, $status, $headers);
130 130
 	}
131 131
 
132 132
 	/**
@@ -138,19 +138,19 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @throws InvalidArgumentException If response is not a valid type.
140 140
 	 */
141
-	public function emit_response( $response ): void {
141
+	public function emit_response($response): void {
142 142
 
143 143
 		// Throw if not a valid response.
144 144
 		if ( ! $response instanceof ResponseInterface
145
-		&& ! $response instanceof WP_HTTP_Response ) {
146
-			throw new InvalidArgumentException( 'Only ResponseInterface & WP_REST_Response responses can be emitted.' );
145
+		&& ! $response instanceof WP_HTTP_Response) {
146
+			throw new InvalidArgumentException('Only ResponseInterface & WP_REST_Response responses can be emitted.');
147 147
 		}
148 148
 
149 149
 		// Based on type, emit the response.
150
-		if ( $response instanceof ResponseInterface ) {
151
-			$this->emit_psr7_response( $response );
150
+		if ($response instanceof ResponseInterface) {
151
+			$this->emit_psr7_response($response);
152 152
 		} else {
153
-			$this->emit_wp_response( $response );
153
+			$this->emit_wp_response($response);
154 154
 		}
155 155
 	}
156 156
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 * @param ResponseInterface $response
161 161
 	 * @return void
162 162
 	 */
163
-	public function emit_psr7_response( ResponseInterface $response ): void {
163
+	public function emit_psr7_response(ResponseInterface $response): void {
164 164
 
165 165
 		// If headers sent, throw headers already sent.
166 166
 		$this->headers_sent();
@@ -172,17 +172,17 @@  discard block
 block discarded – undo
172 172
 			$response->getStatusCode(),
173 173
 			$response->getReasonPhrase()
174 174
 		);
175
-		header( $status_line, true );
175
+		header($status_line, true);
176 176
 
177 177
 		// Append headers.
178
-		foreach ( $this->headers_with_json( $response->getHeaders() )
179
-			as $name => $values ) {
178
+		foreach ($this->headers_with_json($response->getHeaders())
179
+			as $name => $values) {
180 180
 
181 181
 			// If values are an array, join.
182
-			$values = is_array( $values ) ? join( ',', $values ) : (string) $values;
182
+			$values = is_array($values) ? join(',', $values) : (string) $values;
183 183
 
184
-			$response_header = sprintf( '%s: %s', $name, $values );
185
-			header( $response_header, false );
184
+			$response_header = sprintf('%s: %s', $name, $values);
185
+			header($response_header, false);
186 186
 		}
187 187
 
188 188
 		// Emit body.
@@ -196,25 +196,25 @@  discard block
 block discarded – undo
196 196
 	 * @param WP_HTTP_Response $response
197 197
 	 * @return void
198 198
 	 */
199
-	public function emit_wp_response( WP_HTTP_Response $response ): void {
199
+	public function emit_wp_response(WP_HTTP_Response $response): void {
200 200
 
201 201
 		// If headers sent, throw headers already sent.
202 202
 		$this->headers_sent();
203 203
 
204 204
 		// Append headers.
205
-		foreach ( $this->headers_with_json( $response->get_headers() )
206
-			as $name => $values ) {
207
-			$values = is_array( $values ) ? join( ',', $values ) : (string) $values;
205
+		foreach ($this->headers_with_json($response->get_headers())
206
+			as $name => $values) {
207
+			$values = is_array($values) ? join(',', $values) : (string) $values;
208 208
 
209
-			$header = sprintf( '%s: %s', $name, $values );
209
+			$header = sprintf('%s: %s', $name, $values);
210 210
 
211 211
 			// Set the headers.
212
-			header( $header, false );
212
+			header($header, false);
213 213
 		}
214 214
 
215 215
 		// Emit body.
216 216
 		$body = $response->get_data();
217
-		print is_string( $body ) ? $body : wp_json_encode( $body ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
217
+		print is_string($body) ? $body : wp_json_encode($body); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
218 218
 		return; // phpcs:ignore Squiz.PHP.NonExecutableCode.ReturnNotRequired
219 219
 	}
220 220
 
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 	 * @param array<string, mixed> $headers
225 225
 	 * @return array<string, mixed>
226 226
 	 */
227
-	public function headers_with_json( array $headers = array() ): array {
228
-		if ( ! array_key_exists( 'Content-Type', $headers ) ) {
229
-			$headers['Content-Type'] = 'application/json; charset=' . get_option( 'blog_charset' );
227
+	public function headers_with_json(array $headers = array()): array {
228
+		if ( ! array_key_exists('Content-Type', $headers)) {
229
+			$headers['Content-Type'] = 'application/json; charset=' . get_option('blog_charset');
230 230
 		}
231 231
 		return $headers;
232 232
 	}
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
 	 * @throws RuntimeException
239 239
 	 */
240 240
 	protected function headers_sent(): void {
241
-		if ( headers_sent() ) {
242
-			throw new RuntimeException( 'Headers were already sent. The response could not be emitted!' );
241
+		if (headers_sent()) {
242
+			throw new RuntimeException('Headers were already sent. The response could not be emitted!');
243 243
 		}
244 244
 	}
245 245
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	 * @param string|integer|float|object|array<mixed> $data
250 250
 	 * @return \Psr\Http\Message\StreamInterface
251 251
 	 */
252
-	public function stream_from_scalar( $data ): StreamInterface {
253
-		return Stream::create( json_encode( $data ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
252
+	public function stream_from_scalar($data): StreamInterface {
253
+		return Stream::create(json_encode($data) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
254 254
 	}
255 255
 }
Please login to merge, or discard this patch.
src/HTTP_Helper.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
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;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		string $version = '1.1'
87 87
 	): RequestInterface {
88 88
 		return static::get_http()
89
-			->psr7_request( $method, $uri, $headers, $body, $version );
89
+			->psr7_request($method, $uri, $headers, $body, $version);
90 90
 	}
91 91
 
92 92
 	/**
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		?string $reason = null
109 109
 	): ResponseInterface {
110 110
 		return static::get_http()
111
-			->psr7_response( $body, $status, $headers, $version, $reason );
111
+			->psr7_response($body, $status, $headers, $version, $reason);
112 112
 	}
113 113
 
114 114
 	/**
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 		array $headers = array()
126 126
 	): WP_HTTP_Response {
127 127
 		return static::get_http()
128
-			->wp_response( $data, $status, $headers );
128
+			->wp_response($data, $status, $headers);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * @param string|integer|float|object|array<mixed> $value
135 135
 	 * @return StreamInterface
136 136
 	 */
137
-	public static function stream_from_scalar( $value ): StreamInterface {
138
-		return Stream::create( json_encode( $value ) ?: '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
137
+	public static function stream_from_scalar($value): StreamInterface {
138
+		return Stream::create(json_encode($value) ?: ''); // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode
139 139
 	}
140 140
 }
Please login to merge, or discard this patch.