Assets::enqueue_script()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 8
rs 10
1
<?php declare(strict_types = 1);
2
3
namespace WPSteak\Services;
4
5
/** @codeCoverageIgnore */
6
trait Assets {
7
8
	/** @param array<string> $dependencies */
9
	public function enqueue_style(
10
		string $handle,
11
		string $src,
12
		string $file = '',
13
		array $dependencies = [],
14
		string $media = 'all'
15
	): void {
16
		wp_enqueue_style( $handle, $src, $dependencies, $this->generate_file_version( $file ), $media );
17
	}
18
19
	/** @param array<string> $dependencies */
20
	public function enqueue_script(
21
		string $handle,
22
		string $src,
23
		string $file = '',
24
		array $dependencies = [],
25
		bool $in_footer = false
26
	): void {
27
		wp_enqueue_script( $handle, $src, $dependencies, $this->generate_file_version( $file ), $in_footer );
28
	}
29
30
	/** @return int|bool */
31
	protected function generate_file_version( string $file_path ) {
32
		$version = false;
33
34
		if ( $file_path && file_exists( $file_path ) ) {
35
			$version = filemtime( $file_path );
36
		}
37
38
		return $version;
39
	}
40
41
}
42