@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string $handle |
113 | 113 | * @param string $type |
114 | 114 | */ |
115 | - public function __construct( string $handle, string $type ) { |
|
115 | + public function __construct(string $handle, string $type) { |
|
116 | 116 | $this->handle = $handle; |
117 | 117 | $this->type = $type; |
118 | 118 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * @param string $handle |
124 | 124 | * @return self |
125 | 125 | */ |
126 | - public static function script( string $handle ): self { |
|
127 | - return new self( $handle, 'script' ); |
|
126 | + public static function script(string $handle): self { |
|
127 | + return new self($handle, 'script'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @param string $handle |
134 | 134 | * @return self |
135 | 135 | */ |
136 | - public static function style( string $handle ): self { |
|
137 | - return new self( $handle, 'style' ); |
|
136 | + public static function style(string $handle): self { |
|
137 | + return new self($handle, 'style'); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $src |
144 | 144 | * @return self |
145 | 145 | */ |
146 | - public function src( string $src ): self { |
|
146 | + public function src(string $src): self { |
|
147 | 147 | $this->src = $src; |
148 | 148 | return $this; |
149 | 149 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param string ...$deps |
155 | 155 | * @return self |
156 | 156 | */ |
157 | - public function deps( string ...$deps ): self { |
|
157 | + public function deps(string ...$deps): self { |
|
158 | 158 | $this->deps = $deps; |
159 | 159 | return $this; |
160 | 160 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param string $ver |
166 | 166 | * @return self |
167 | 167 | */ |
168 | - public function ver( string $ver ): self { |
|
168 | + public function ver(string $ver): self { |
|
169 | 169 | $this->ver = $ver; |
170 | 170 | return $this; |
171 | 171 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @param string $media |
177 | 177 | * @return self |
178 | 178 | */ |
179 | - public function media( string $media ): self { |
|
179 | + public function media(string $media): self { |
|
180 | 180 | $this->media = $media; |
181 | 181 | return $this; |
182 | 182 | } |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | * @return self |
189 | 189 | */ |
190 | 190 | public function lastest_version(): self { |
191 | - if ( $this->does_file_exist( $this->src ) ) { |
|
191 | + if ($this->does_file_exist($this->src)) { |
|
192 | 192 | |
193 | - $headers = get_headers( $this->src, 1 ); |
|
193 | + $headers = get_headers($this->src, 1); |
|
194 | 194 | |
195 | - if ( is_array( $headers ) |
|
196 | - && array_key_exists( 'Last-Modified', $headers ) |
|
195 | + if (is_array($headers) |
|
196 | + && array_key_exists('Last-Modified', $headers) |
|
197 | 197 | ) { |
198 | - $this->ver = strtotime( $headers['Last-Modified'] ); |
|
198 | + $this->ver = strtotime($headers['Last-Modified']); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | return $this; |
@@ -207,16 +207,16 @@ discard block |
||
207 | 207 | * @param string $url The URL of the file being checked. |
208 | 208 | * @return boolean true if it does, false if it doesnt. |
209 | 209 | */ |
210 | - private function does_file_exist( string $url ): bool { |
|
211 | - $ch = curl_init( $url ); |
|
212 | - if ( ! $ch ) { |
|
210 | + private function does_file_exist(string $url): bool { |
|
211 | + $ch = curl_init($url); |
|
212 | + if ( ! $ch) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | - curl_setopt( $ch, CURLOPT_NOBODY, true ); |
|
216 | - curl_setopt( $ch, CURLOPT_TIMEOUT_MS, 50 ); |
|
217 | - curl_exec( $ch ); |
|
218 | - $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
|
219 | - curl_close( $ch ); |
|
215 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
216 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 50); |
|
217 | + curl_exec($ch); |
|
218 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
219 | + curl_close($ch); |
|
220 | 220 | return $http_code === 200; |
221 | 221 | } |
222 | 222 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param boolean $footer |
227 | 227 | * @return self |
228 | 228 | */ |
229 | - public function footer( bool $footer = true ): self { |
|
229 | + public function footer(bool $footer = true): self { |
|
230 | 230 | $this->footer = $footer; |
231 | 231 | return $this; |
232 | 232 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @param boolean $inline |
248 | 248 | * @return self |
249 | 249 | */ |
250 | - public function inline( bool $inline = true ):self { |
|
250 | + public function inline(bool $inline = true):self { |
|
251 | 251 | $this->inline = $inline; |
252 | 252 | return $this; |
253 | 253 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @param array<string, mixed> $args |
259 | 259 | * @return self |
260 | 260 | */ |
261 | - public function localize( array $args ): self { |
|
261 | + public function localize(array $args): self { |
|
262 | 262 | $this->localize = $args; |
263 | 263 | return $this; |
264 | 264 | } |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | * @param string $flag |
270 | 270 | * @return self |
271 | 271 | */ |
272 | - public function flag( string $flag ): self { |
|
273 | - $this->attributes[ $flag ] = null; |
|
272 | + public function flag(string $flag): self { |
|
273 | + $this->attributes[$flag] = null; |
|
274 | 274 | return $this; |
275 | 275 | } |
276 | 276 | |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @param string $value |
282 | 282 | * @return self |
283 | 283 | */ |
284 | - public function attribute( string $key, string $value ): self { |
|
285 | - $this->attributes[ $key ] = $value; |
|
284 | + public function attribute(string $key, string $value): self { |
|
285 | + $this->attributes[$key] = $value; |
|
286 | 286 | return $this; |
287 | 287 | } |
288 | 288 | |
@@ -293,8 +293,8 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public function defer(): self { |
295 | 295 | // Remove ASYNC if set. |
296 | - if ( \array_key_exists( 'async', $this->attributes ) ) { |
|
297 | - unset( $this->attributes['async'] ); |
|
296 | + if (\array_key_exists('async', $this->attributes)) { |
|
297 | + unset($this->attributes['async']); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | $this->attributes['defer'] = ''; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function async(): self { |
310 | 310 | // Remove DEFER if set. |
311 | - if ( \array_key_exists( 'defer', $this->attributes ) ) { |
|
312 | - unset( $this->attributes['defer'] ); |
|
311 | + if (\array_key_exists('defer', $this->attributes)) { |
|
312 | + unset($this->attributes['defer']); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | $this->attributes['async'] = ''; |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | * @return void |
323 | 323 | */ |
324 | 324 | public function register(): void { |
325 | - if ( $this->type === 'script' ) { |
|
325 | + if ($this->type === 'script') { |
|
326 | 326 | $this->register_script(); |
327 | 327 | } |
328 | 328 | |
329 | - if ( $this->type === 'style' ) { |
|
329 | + if ($this->type === 'style') { |
|
330 | 330 | $this->register_style(); |
331 | 331 | } |
332 | 332 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | private function register_script() { |
358 | 358 | |
359 | - if ( $this->inline ) { |
|
359 | + if ($this->inline) { |
|
360 | 360 | \wp_register_script( |
361 | 361 | $this->handle, |
362 | 362 | '', |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | $this->ver, |
365 | 365 | $this->footer |
366 | 366 | ); |
367 | - if ( $this->does_file_exist( $this->src ) ) { |
|
368 | - \wp_add_inline_script( $this->handle, file_get_contents( $this->src ) ?: '' ); |
|
367 | + if ($this->does_file_exist($this->src)) { |
|
368 | + \wp_add_inline_script($this->handle, file_get_contents($this->src) ?: ''); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | 371 | wp_register_script( |
@@ -377,11 +377,11 @@ discard block |
||
377 | 377 | ); |
378 | 378 | } |
379 | 379 | |
380 | - if ( ! empty( $this->localize ) ) { |
|
381 | - \wp_localize_script( $this->handle, $this->handle, $this->localize ); |
|
380 | + if ( ! empty($this->localize)) { |
|
381 | + \wp_localize_script($this->handle, $this->handle, $this->localize); |
|
382 | 382 | } |
383 | 383 | |
384 | - \wp_enqueue_script( $this->handle ); |
|
384 | + \wp_enqueue_script($this->handle); |
|
385 | 385 | |
386 | 386 | $this->add_script_attributes(); |
387 | 387 | } |
@@ -396,19 +396,19 @@ discard block |
||
396 | 396 | $attributes = $this->get_attributes(); |
397 | 397 | |
398 | 398 | // Bail if we have no attributes. |
399 | - if ( 0 === count( $attributes ) ) { |
|
399 | + if (0 === count($attributes)) { |
|
400 | 400 | return; |
401 | 401 | } |
402 | 402 | |
403 | 403 | // Add to any scripts. |
404 | 404 | add_filter( |
405 | 405 | 'script_loader_tag', |
406 | - function( string $tag, string $handle, string $source ) use ( $attributes ): string { |
|
406 | + function(string $tag, string $handle, string $source) use ($attributes): string { |
|
407 | 407 | // Bail if not our script. |
408 | - if ( $this->handle !== $handle ) { |
|
408 | + if ($this->handle !== $handle) { |
|
409 | 409 | return $tag; |
410 | 410 | } |
411 | - return sprintf( '<script type="text/javascript" src="%s" %s></script>', $source, join( ' ', $attributes ) ); //phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
|
411 | + return sprintf('<script type="text/javascript" src="%s" %s></script>', $source, join(' ', $attributes)); //phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
|
412 | 412 | }, |
413 | 413 | 1, |
414 | 414 | 3 |
@@ -425,16 +425,16 @@ discard block |
||
425 | 425 | $attributes = $this->get_attributes(); |
426 | 426 | |
427 | 427 | // Bail if we have no attributes. |
428 | - if ( 0 === count( $attributes ) ) { |
|
428 | + if (0 === count($attributes)) { |
|
429 | 429 | return; |
430 | 430 | } |
431 | 431 | |
432 | 432 | // Add to any relevant styles. |
433 | 433 | add_filter( |
434 | 434 | 'style_loader_tag', |
435 | - function( string $tag, string $handle, string $href, string $media ) use ( $attributes ): string { |
|
435 | + function(string $tag, string $handle, string $href, string $media) use ($attributes): string { |
|
436 | 436 | // Bail if not our script. |
437 | - if ( $this->handle !== $handle ) { |
|
437 | + if ($this->handle !== $handle) { |
|
438 | 438 | return $tag; |
439 | 439 | } |
440 | 440 | return sprintf( |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | $handle, |
443 | 443 | $href, |
444 | 444 | $media, |
445 | - join( ' ', $attributes ) |
|
445 | + join(' ', $attributes) |
|
446 | 446 | ); |
447 | 447 | }, |
448 | 448 | 1, |
@@ -457,12 +457,12 @@ discard block |
||
457 | 457 | */ |
458 | 458 | private function get_attributes():array { |
459 | 459 | return array_map( |
460 | - function( string $key, ?string $value ): string { |
|
460 | + function(string $key, ?string $value): string { |
|
461 | 461 | return null === $value |
462 | 462 | ? "{$key}" |
463 | 463 | : "{$key}='{$value}'"; |
464 | 464 | }, |
465 | - array_keys( $this->attributes ), |
|
465 | + array_keys($this->attributes), |
|
466 | 466 | $this->attributes |
467 | 467 | ); |
468 | 468 | } |