Image::initializes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WPDFI;
4
5
/**
6
 * This class handle all actions related with Image
7
 *
8
 * @author Duc Bui Quang <[email protected]>
9
 * @since 1.0.0
10
 */
11
12
use WPDFI\Traits\Singleton;
13
14
final class Image
15
{
16
	use Singleton;
17
18
	/**
19
	 * @traitDoc
20
	 */
21
	public function initializes() 
22
	{
23
		//
24
	}
25
26
	/**
27
	 * Get all image size names
28
	 *
29
	 * @since 1.0.0
30
	 * @return array
31
	 */
32
	public function get_size_names() {
33
34
		return \get_intermediate_image_sizes();
35
		
36
	}
37
38
	/**
39
	 * Get image size dimensions
40
	 *
41
	 * @param string $size_name
42
	 * @since 1.0.0
43
	 * @return array
44
	 */
45
	public function get_size_dimensions($size_name) {
46
		global $_wp_additional_image_sizes;
47
48
		$data = [];
49
		// Default size
50
		if ( in_array( $size_name, ['thumbnail', 'medium', 'medium_large', 'large'] ) ) {
51
			$data['width']  = get_option( "{$size_name}_size_w" );
52
			$data['height'] = get_option( "{$size_name}_size_h" );
53
		// Additional size
54
		} elseif ( isset( $_wp_additional_image_sizes[ $size_name ] ) ) {
55
			$data['width'] = $_wp_additional_image_sizes[ $size_name ]['width'];
56
			$data['height'] = $_wp_additional_image_sizes[ $size_name ]['height'];
57
		}
58
59
		return $data;
60
	}
61
62
	/**
63
	 * Get all size names and its dimensions
64
	 *
65
	 * @since 1.0.0
66
	 * @return array
67
	 */
68
	public function get_size_names_and_dimensions() {
69
		$data = [];
70
71
		foreach($this->get_size_names() as $size_name) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
72
			$data[$size_name] = $this->get_size_dimensions($size_name);
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
73
		}
74
75
		return $data;
76
	}
77
}