@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param string $handle |
126 | 126 | * @param string $type |
127 | 127 | */ |
128 | - public function __construct( string $handle, string $type ) { |
|
128 | + public function __construct(string $handle, string $type) { |
|
129 | 129 | $this->handle = $handle; |
130 | 130 | $this->type = $type; |
131 | 131 | } |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $handle |
137 | 137 | * @return self |
138 | 138 | */ |
139 | - public static function script( string $handle ): self { |
|
140 | - return new self( $handle, 'script' ); |
|
139 | + public static function script(string $handle): self { |
|
140 | + return new self($handle, 'script'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @param string $handle |
147 | 147 | * @return self |
148 | 148 | */ |
149 | - public static function style( string $handle ): self { |
|
150 | - return new self( $handle, 'style' ); |
|
149 | + public static function style(string $handle): self { |
|
150 | + return new self($handle, 'style'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param string $src |
157 | 157 | * @return self |
158 | 158 | */ |
159 | - public function src( string $src ): self { |
|
159 | + public function src(string $src): self { |
|
160 | 160 | $this->src = $src; |
161 | 161 | return $this; |
162 | 162 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @param string ...$deps |
168 | 168 | * @return self |
169 | 169 | */ |
170 | - public function deps( string ...$deps ): self { |
|
171 | - $this->deps = array_values( $deps ); |
|
170 | + public function deps(string ...$deps): self { |
|
171 | + $this->deps = array_values($deps); |
|
172 | 172 | return $this; |
173 | 173 | } |
174 | 174 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string $ver |
179 | 179 | * @return self |
180 | 180 | */ |
181 | - public function ver( string $ver ): self { |
|
181 | + public function ver(string $ver): self { |
|
182 | 182 | $this->ver = $ver; |
183 | 183 | return $this; |
184 | 184 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @param string $media |
190 | 190 | * @return self |
191 | 191 | */ |
192 | - public function media( string $media ): self { |
|
192 | + public function media(string $media): self { |
|
193 | 193 | $this->media = $media; |
194 | 194 | return $this; |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @deprecated 1.3.0 |
202 | 202 | */ |
203 | 203 | public function lastest_version():self { |
204 | - trigger_error( 'Method ' . __METHOD__ . ' is deprecated', E_USER_DEPRECATED ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error |
|
204 | + trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error |
|
205 | 205 | return $this->latest_version(); |
206 | 206 | } |
207 | 207 | |
@@ -212,17 +212,17 @@ discard block |
||
212 | 212 | * @return self |
213 | 213 | */ |
214 | 214 | public function latest_version(): self { |
215 | - if ( $this->does_file_exist( $this->src ) ) { |
|
215 | + if ($this->does_file_exist($this->src)) { |
|
216 | 216 | |
217 | 217 | // If php8 or above set as bool, else int |
218 | - $associate = ( PHP_VERSION_ID >= 80000 ) ? true : 1; |
|
218 | + $associate = (PHP_VERSION_ID >= 80000) ? true : 1; |
|
219 | 219 | |
220 | - $headers = get_headers( $this->src, $associate ); |
|
220 | + $headers = get_headers($this->src, $associate); |
|
221 | 221 | |
222 | - if ( is_array( $headers ) |
|
223 | - && array_key_exists( 'Last-Modified', $headers ) |
|
222 | + if (is_array($headers) |
|
223 | + && array_key_exists('Last-Modified', $headers) |
|
224 | 224 | ) { |
225 | - $this->ver = strtotime( $headers['Last-Modified'] ); |
|
225 | + $this->ver = strtotime($headers['Last-Modified']); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | return $this; |
@@ -234,16 +234,16 @@ discard block |
||
234 | 234 | * @param string $url The URL of the file being checked. |
235 | 235 | * @return boolean true if it does, false if it doesnt. |
236 | 236 | */ |
237 | - private function does_file_exist( string $url ): bool { |
|
238 | - $ch = curl_init( $url ); |
|
239 | - if ( ! $ch ) { |
|
237 | + private function does_file_exist(string $url): bool { |
|
238 | + $ch = curl_init($url); |
|
239 | + if ( ! $ch) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | - curl_setopt( $ch, CURLOPT_NOBODY, true ); |
|
243 | - curl_setopt( $ch, CURLOPT_TIMEOUT_MS, 50 ); |
|
244 | - curl_exec( $ch ); |
|
245 | - $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); |
|
246 | - curl_close( $ch ); |
|
242 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
|
243 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 50); |
|
244 | + curl_exec($ch); |
|
245 | + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
246 | + curl_close($ch); |
|
247 | 247 | return $http_code === 200; |
248 | 248 | } |
249 | 249 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param boolean $footer |
254 | 254 | * @return self |
255 | 255 | */ |
256 | - public function footer( bool $footer = true ): self { |
|
256 | + public function footer(bool $footer = true): self { |
|
257 | 257 | $this->footer = $footer; |
258 | 258 | return $this; |
259 | 259 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @param boolean $inline |
275 | 275 | * @return self |
276 | 276 | */ |
277 | - public function inline( bool $inline = true ):self { |
|
277 | + public function inline(bool $inline = true):self { |
|
278 | 278 | $this->inline = $inline; |
279 | 279 | return $this; |
280 | 280 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @param array<string, mixed> $args |
286 | 286 | * @return self |
287 | 287 | */ |
288 | - public function localize( array $args ): self { |
|
288 | + public function localize(array $args): self { |
|
289 | 289 | $this->localize = $args; |
290 | 290 | return $this; |
291 | 291 | } |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | * @param string $flag |
297 | 297 | * @return self |
298 | 298 | */ |
299 | - public function flag( string $flag ): self { |
|
300 | - $this->attributes[ $flag ] = null; |
|
299 | + public function flag(string $flag): self { |
|
300 | + $this->attributes[$flag] = null; |
|
301 | 301 | return $this; |
302 | 302 | } |
303 | 303 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * @param string $value |
309 | 309 | * @return self |
310 | 310 | */ |
311 | - public function attribute( string $key, string $value ): self { |
|
312 | - $this->attributes[ $key ] = $value; |
|
311 | + public function attribute(string $key, string $value): self { |
|
312 | + $this->attributes[$key] = $value; |
|
313 | 313 | return $this; |
314 | 314 | } |
315 | 315 | |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function defer(): self { |
322 | 322 | // Remove ASYNC if set. |
323 | - if ( \array_key_exists( 'async', $this->attributes ) ) { |
|
324 | - unset( $this->attributes['async'] ); |
|
323 | + if (\array_key_exists('async', $this->attributes)) { |
|
324 | + unset($this->attributes['async']); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | $this->attributes['defer'] = ''; |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function async(): self { |
337 | 337 | // Remove DEFER if set. |
338 | - if ( \array_key_exists( 'defer', $this->attributes ) ) { |
|
339 | - unset( $this->attributes['defer'] ); |
|
338 | + if (\array_key_exists('defer', $this->attributes)) { |
|
339 | + unset($this->attributes['defer']); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $this->attributes['async'] = ''; |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * @param bool $for_block Denotes if being enqueued for a block. |
350 | 350 | * @return self |
351 | 351 | */ |
352 | - public function for_block( bool $for_block = true ) : self { |
|
352 | + public function for_block(bool $for_block = true) : self { |
|
353 | 353 | $this->for_block = $for_block; |
354 | 354 | return $this; |
355 | 355 | } |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | * @return void |
361 | 361 | */ |
362 | 362 | public function register(): void { |
363 | - if ( $this->type === 'script' ) { |
|
363 | + if ($this->type === 'script') { |
|
364 | 364 | $this->register_script(); |
365 | 365 | } |
366 | 366 | |
367 | - if ( $this->type === 'style' ) { |
|
367 | + if ($this->type === 'style') { |
|
368 | 368 | $this->register_style(); |
369 | 369 | } |
370 | 370 | } |
@@ -383,8 +383,8 @@ discard block |
||
383 | 383 | $this->ver, |
384 | 384 | $this->media |
385 | 385 | ); |
386 | - if ( false === $this->for_block ) { |
|
387 | - wp_enqueue_style( $this->handle ); |
|
386 | + if (false === $this->for_block) { |
|
387 | + wp_enqueue_style($this->handle); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | $this->add_style_attributes(); |
@@ -407,18 +407,18 @@ discard block |
||
407 | 407 | ); |
408 | 408 | |
409 | 409 | // Maybe add as an inline script. |
410 | - if ( $this->inline && $this->does_file_exist( $this->src ) ) { |
|
411 | - \wp_add_inline_script( $this->handle, file_get_contents( $this->src ) ?: '' ); |
|
410 | + if ($this->inline && $this->does_file_exist($this->src)) { |
|
411 | + \wp_add_inline_script($this->handle, file_get_contents($this->src) ?: ''); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | // Localize all values if defined. |
415 | - if ( ! empty( $this->localize ) ) { |
|
416 | - \wp_localize_script( $this->handle, $this->handle, $this->localize ); |
|
415 | + if ( ! empty($this->localize)) { |
|
416 | + \wp_localize_script($this->handle, $this->handle, $this->localize); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | // Enqueue file if not used for a block. |
420 | - if ( false === $this->for_block ) { |
|
421 | - \wp_enqueue_script( $this->handle ); |
|
420 | + if (false === $this->for_block) { |
|
421 | + \wp_enqueue_script($this->handle); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | $this->add_script_attributes(); |
@@ -434,19 +434,19 @@ discard block |
||
434 | 434 | $attributes = $this->get_script_attributes(); |
435 | 435 | |
436 | 436 | // Bail if we have no attributes. |
437 | - if ( 0 === count( $this->get_attributes() ) && $this->script_type === 'text/javascript' ) { |
|
437 | + if (0 === count($this->get_attributes()) && $this->script_type === 'text/javascript') { |
|
438 | 438 | return; |
439 | 439 | } |
440 | 440 | |
441 | 441 | // Add to any scripts. |
442 | 442 | add_filter( |
443 | 443 | 'script_loader_tag', |
444 | - function( string $tag, string $handle, string $source ) use ( $attributes ): string { |
|
444 | + function(string $tag, string $handle, string $source) use ($attributes): string { |
|
445 | 445 | // Bail if not our script. |
446 | - if ( $this->handle !== $handle ) { |
|
446 | + if ($this->handle !== $handle) { |
|
447 | 447 | return $tag; |
448 | 448 | } |
449 | - return sprintf( '<script type="%s" src="%s" %s></script>', $this->script_type, $source, join( ' ', $attributes ) ); //phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
|
449 | + return sprintf('<script type="%s" src="%s" %s></script>', $this->script_type, $source, join(' ', $attributes)); //phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
|
450 | 450 | }, |
451 | 451 | 1, |
452 | 452 | 3 |
@@ -461,14 +461,14 @@ discard block |
||
461 | 461 | private function get_script_attributes(): array { |
462 | 462 | $attributes = $this->get_attributes(); |
463 | 463 | // Loop through and look for any that start with 'id=' |
464 | - foreach ( $attributes as $key => $value ) { |
|
465 | - if ( \strpos( $value, 'id=' ) === 0 ) { |
|
464 | + foreach ($attributes as $key => $value) { |
|
465 | + if (\strpos($value, 'id=') === 0) { |
|
466 | 466 | return $attributes; |
467 | 467 | } |
468 | 468 | } |
469 | 469 | |
470 | 470 | // Add to attributes |
471 | - $attributes[] = \sprintf( "id='%s'", "{$this->handle}-js" ); |
|
471 | + $attributes[] = \sprintf("id='%s'", "{$this->handle}-js"); |
|
472 | 472 | return $attributes; |
473 | 473 | } |
474 | 474 | |
@@ -482,16 +482,16 @@ discard block |
||
482 | 482 | $attributes = $this->get_attributes(); |
483 | 483 | |
484 | 484 | // Bail if we have no attributes. |
485 | - if ( 0 === count( $attributes ) ) { |
|
485 | + if (0 === count($attributes)) { |
|
486 | 486 | return; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Add to any relevant styles. |
490 | 490 | add_filter( |
491 | 491 | 'style_loader_tag', |
492 | - function( string $tag, string $handle, string $href, string $media ) use ( $attributes ): string { |
|
492 | + function(string $tag, string $handle, string $href, string $media) use ($attributes): string { |
|
493 | 493 | // Bail if not our script. |
494 | - if ( $this->handle !== $handle ) { |
|
494 | + if ($this->handle !== $handle) { |
|
495 | 495 | return $tag; |
496 | 496 | } |
497 | 497 | return sprintf( |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | $handle, |
500 | 500 | $href, |
501 | 501 | $media, |
502 | - join( ' ', $attributes ) |
|
502 | + join(' ', $attributes) |
|
503 | 503 | ); |
504 | 504 | }, |
505 | 505 | 1, |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @param string $script_type Denotes the script type. |
514 | 514 | * @return self |
515 | 515 | */ |
516 | - public function script_type( string $script_type ) { |
|
516 | + public function script_type(string $script_type) { |
|
517 | 517 | $this->script_type = $script_type; |
518 | 518 | return $this; |
519 | 519 | } |
@@ -525,12 +525,12 @@ discard block |
||
525 | 525 | */ |
526 | 526 | private function get_attributes():array { |
527 | 527 | return array_map( |
528 | - function( string $key, ?string $value ): string { |
|
528 | + function(string $key, ?string $value): string { |
|
529 | 529 | return null === $value |
530 | 530 | ? "{$key}" |
531 | 531 | : "{$key}='{$value}'"; |
532 | 532 | }, |
533 | - array_keys( $this->attributes ), |
|
533 | + array_keys($this->attributes), |
|
534 | 534 | $this->attributes |
535 | 535 | ); |
536 | 536 | } |