Assets   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A enqueue_style() 0 8 1
A enqueue_script() 0 8 1
A generate_file_version() 0 8 3
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