@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $handle |
119 | 119 | * @param string $type |
120 | 120 | */ |
121 | - public function __construct( string $handle, string $type ) { |
|
121 | + public function __construct(string $handle, string $type) { |
|
122 | 122 | $this->handle = $handle; |
123 | 123 | $this->type = $type; |
124 | 124 | } |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @param string $handle |
130 | 130 | * @return self |
131 | 131 | */ |
132 | - public static function script( string $handle ): self { |
|
133 | - return new self( $handle, 'script' ); |
|
132 | + public static function script(string $handle): self { |
|
133 | + return new self($handle, 'script'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $handle |
140 | 140 | * @return self |
141 | 141 | */ |
142 | - public static function style( string $handle ): self { |
|
143 | - return new self( $handle, 'style' ); |
|
142 | + public static function style(string $handle): self { |
|
143 | + return new self($handle, 'style'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param string $src |
150 | 150 | * @return self |
151 | 151 | */ |
152 | - public function src( string $src ): self { |
|
152 | + public function src(string $src): self { |
|
153 | 153 | $this->src = $src; |
154 | 154 | return $this; |
155 | 155 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string ...$deps |
161 | 161 | * @return self |
162 | 162 | */ |
163 | - public function deps( string ...$deps ): self { |
|
163 | + public function deps(string ...$deps): self { |
|
164 | 164 | $this->deps = $deps; |
165 | 165 | return $this; |
166 | 166 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param string $ver |
172 | 172 | * @return self |
173 | 173 | */ |
174 | - public function ver( string $ver ): self { |
|
174 | + public function ver(string $ver): self { |
|
175 | 175 | $this->ver = $ver; |
176 | 176 | return $this; |
177 | 177 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @param string $media |
183 | 183 | * @return self |
184 | 184 | */ |
185 | - public function media( string $media ): self { |
|
185 | + public function media(string $media): self { |
|
186 | 186 | $this->media = $media; |
187 | 187 | return $this; |
188 | 188 | } |
@@ -194,14 +194,14 @@ discard block |
||
194 | 194 | * @return self |
195 | 195 | */ |
196 | 196 | public function lastest_version(): self { |
197 | - if ( $this->does_file_exist( $this->src ) ) { |
|
197 | + if ($this->does_file_exist($this->src)) { |
|
198 | 198 | |
199 | - $headers = get_headers( $this->src, 1 ); |
|
199 | + $headers = get_headers($this->src, 1); |
|
200 | 200 | |
201 | - if ( is_array( $headers ) |
|
202 | - && array_key_exists( 'Last-Modified', $headers ) |
|
201 | + if (is_array($headers) |
|
202 | + && array_key_exists('Last-Modified', $headers) |
|
203 | 203 | ) { |
204 | - $this->ver = strtotime( $headers['Last-Modified'] ); |
|
204 | + $this->ver = strtotime($headers['Last-Modified']); |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | return $this; |
@@ -213,16 +213,16 @@ discard block |
||
213 | 213 | * @param string $url The URL of the file being checked. |
214 | 214 | * @return boolean true if it does, false if it doesnt. |
215 | 215 | */ |
216 | - private function does_file_exist( string $url ): bool { |
|
217 | - $ch = curl_init( $url ); |
|
218 | - if ( ! $ch ) { |
|
216 | + private function does_file_exist(string $url): bool { |
|
217 | + $ch = curl_init($url); |
|
218 | + if ( ! $ch) { |
|
219 | 219 | return false; |
220 | 220 | } |
221 | - curl_setopt( $ch, CURLOPT_NOBODY, true ); |
|
222 | - curl_setopt( $ch, CURLOPT_TIMEOUT_MS, 50 ); |
|
223 | - curl_exec( $ch ); |
|
224 | - $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
|
225 | - curl_close( $ch ); |
|
221 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
222 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 50); |
|
223 | + curl_exec($ch); |
|
224 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
225 | + curl_close($ch); |
|
226 | 226 | return $http_code === 200; |
227 | 227 | } |
228 | 228 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param boolean $footer |
233 | 233 | * @return self |
234 | 234 | */ |
235 | - public function footer( bool $footer = true ): self { |
|
235 | + public function footer(bool $footer = true): self { |
|
236 | 236 | $this->footer = $footer; |
237 | 237 | return $this; |
238 | 238 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param boolean $inline |
254 | 254 | * @return self |
255 | 255 | */ |
256 | - public function inline( bool $inline = true ):self { |
|
256 | + public function inline(bool $inline = true):self { |
|
257 | 257 | $this->inline = $inline; |
258 | 258 | return $this; |
259 | 259 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param array<string, mixed> $args |
265 | 265 | * @return self |
266 | 266 | */ |
267 | - public function localize( array $args ): self { |
|
267 | + public function localize(array $args): self { |
|
268 | 268 | $this->localize = $args; |
269 | 269 | return $this; |
270 | 270 | } |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * @param string $flag |
276 | 276 | * @return self |
277 | 277 | */ |
278 | - public function flag( string $flag ): self { |
|
279 | - $this->attributes[ $flag ] = null; |
|
278 | + public function flag(string $flag): self { |
|
279 | + $this->attributes[$flag] = null; |
|
280 | 280 | return $this; |
281 | 281 | } |
282 | 282 | |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | * @param string $value |
288 | 288 | * @return self |
289 | 289 | */ |
290 | - public function attribute( string $key, string $value ): self { |
|
291 | - $this->attributes[ $key ] = $value; |
|
290 | + public function attribute(string $key, string $value): self { |
|
291 | + $this->attributes[$key] = $value; |
|
292 | 292 | return $this; |
293 | 293 | } |
294 | 294 | |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | */ |
300 | 300 | public function defer(): self { |
301 | 301 | // Remove ASYNC if set. |
302 | - if ( \array_key_exists( 'async', $this->attributes ) ) { |
|
303 | - unset( $this->attributes['async'] ); |
|
302 | + if (\array_key_exists('async', $this->attributes)) { |
|
303 | + unset($this->attributes['async']); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | $this->attributes['defer'] = ''; |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function async(): self { |
316 | 316 | // Remove DEFER if set. |
317 | - if ( \array_key_exists( 'defer', $this->attributes ) ) { |
|
318 | - unset( $this->attributes['defer'] ); |
|
317 | + if (\array_key_exists('defer', $this->attributes)) { |
|
318 | + unset($this->attributes['defer']); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | $this->attributes['async'] = ''; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @param bool $for_block Denotes if being enqueued for a block. |
329 | 329 | * @return self |
330 | 330 | */ |
331 | - public function for_block( bool $for_block = true ) : self { |
|
331 | + public function for_block(bool $for_block = true) : self { |
|
332 | 332 | $this->for_block = $for_block; |
333 | 333 | return $this; |
334 | 334 | } |
@@ -339,11 +339,11 @@ discard block |
||
339 | 339 | * @return void |
340 | 340 | */ |
341 | 341 | public function register(): void { |
342 | - if ( $this->type === 'script' ) { |
|
342 | + if ($this->type === 'script') { |
|
343 | 343 | $this->register_script(); |
344 | 344 | } |
345 | 345 | |
346 | - if ( $this->type === 'style' ) { |
|
346 | + if ($this->type === 'style') { |
|
347 | 347 | $this->register_style(); |
348 | 348 | } |
349 | 349 | } |
@@ -362,8 +362,8 @@ discard block |
||
362 | 362 | $this->ver, |
363 | 363 | $this->media |
364 | 364 | ); |
365 | - if ( false === $this->for_block ) { |
|
366 | - wp_enqueue_style( $this->handle ); |
|
365 | + if (false === $this->for_block) { |
|
366 | + wp_enqueue_style($this->handle); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $this->add_style_attributes(); |
@@ -386,18 +386,18 @@ discard block |
||
386 | 386 | ); |
387 | 387 | |
388 | 388 | // Maybe add as an inline script. |
389 | - if ( $this->inline && $this->does_file_exist( $this->src ) ) { |
|
390 | - \wp_add_inline_script( $this->handle, file_get_contents( $this->src ) ?: '' ); |
|
389 | + if ($this->inline && $this->does_file_exist($this->src)) { |
|
390 | + \wp_add_inline_script($this->handle, file_get_contents($this->src) ?: ''); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // Localize all values if defined. |
394 | - if ( ! empty( $this->localize ) ) { |
|
395 | - \wp_localize_script( $this->handle, $this->handle, $this->localize ); |
|
394 | + if ( ! empty($this->localize)) { |
|
395 | + \wp_localize_script($this->handle, $this->handle, $this->localize); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | // Enqueue file if not used for a block. |
399 | - if ( false === $this->for_block ) { |
|
400 | - \wp_enqueue_script( $this->handle ); |
|
399 | + if (false === $this->for_block) { |
|
400 | + \wp_enqueue_script($this->handle); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | $this->add_script_attributes(); |
@@ -413,19 +413,19 @@ discard block |
||
413 | 413 | $attributes = $this->get_attributes(); |
414 | 414 | |
415 | 415 | // Bail if we have no attributes. |
416 | - if ( 0 === count( $attributes ) ) { |
|
416 | + if (0 === count($attributes)) { |
|
417 | 417 | return; |
418 | 418 | } |
419 | 419 | |
420 | 420 | // Add to any scripts. |
421 | 421 | add_filter( |
422 | 422 | 'script_loader_tag', |
423 | - function( string $tag, string $handle, string $source ) use ( $attributes ): string { |
|
423 | + function(string $tag, string $handle, string $source) use ($attributes): string { |
|
424 | 424 | // Bail if not our script. |
425 | - if ( $this->handle !== $handle ) { |
|
425 | + if ($this->handle !== $handle) { |
|
426 | 426 | return $tag; |
427 | 427 | } |
428 | - return sprintf( '<script type="text/javascript" src="%s" %s></script>', $source, join( ' ', $attributes ) ); //phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
|
428 | + return sprintf('<script type="text/javascript" src="%s" %s></script>', $source, join(' ', $attributes)); //phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
|
429 | 429 | }, |
430 | 430 | 1, |
431 | 431 | 3 |
@@ -442,16 +442,16 @@ discard block |
||
442 | 442 | $attributes = $this->get_attributes(); |
443 | 443 | |
444 | 444 | // Bail if we have no attributes. |
445 | - if ( 0 === count( $attributes ) ) { |
|
445 | + if (0 === count($attributes)) { |
|
446 | 446 | return; |
447 | 447 | } |
448 | 448 | |
449 | 449 | // Add to any relevant styles. |
450 | 450 | add_filter( |
451 | 451 | 'style_loader_tag', |
452 | - function( string $tag, string $handle, string $href, string $media ) use ( $attributes ): string { |
|
452 | + function(string $tag, string $handle, string $href, string $media) use ($attributes): string { |
|
453 | 453 | // Bail if not our script. |
454 | - if ( $this->handle !== $handle ) { |
|
454 | + if ($this->handle !== $handle) { |
|
455 | 455 | return $tag; |
456 | 456 | } |
457 | 457 | return sprintf( |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $handle, |
460 | 460 | $href, |
461 | 461 | $media, |
462 | - join( ' ', $attributes ) |
|
462 | + join(' ', $attributes) |
|
463 | 463 | ); |
464 | 464 | }, |
465 | 465 | 1, |
@@ -474,12 +474,12 @@ discard block |
||
474 | 474 | */ |
475 | 475 | private function get_attributes():array { |
476 | 476 | return array_map( |
477 | - function( string $key, ?string $value ): string { |
|
477 | + function(string $key, ?string $value): string { |
|
478 | 478 | return null === $value |
479 | 479 | ? "{$key}" |
480 | 480 | : "{$key}='{$value}'"; |
481 | 481 | }, |
482 | - array_keys( $this->attributes ), |
|
482 | + array_keys($this->attributes), |
|
483 | 483 | $this->attributes |
484 | 484 | ); |
485 | 485 | } |