Completed
Push — master ( eef885...465d0c )
by
unknown
30:08 queued 12:49
created

size_util::convert_to()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 15
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 14
nc 9
nop 3
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
1
<?php namespace eoxia;
2
3
if ( !defined( 'ABSPATH' ) ) exit;
4
5
/**
6
 * @author Jimmy Latour <[email protected]>
7
 * @version 1.0
8
 */
9
10
if ( ! class_exists( '\eoxia\size_util' ) ) {
11
	class size_util extends \eoxia\Singleton_Util {
12
		protected function construct() {}
13
14
		/**
15
	  * convert to - Convert format to "oc" or deconvert
16
	  *
17
	  * @param float $input
18
	  * @param string $format
19
	  * @param boolean $convert
20
	  * @return float|number
21
	  */
22
	  public function convert_to($input, $format, $convert = true) {
23
			if($format == 'oc')
24
				return $input;
25
			$multiple = 0;
26
			if($format == 'ko')
27
				$multiple = 1024;
28
			else if($format == 'mo')
29
				$multiple = 1048576;
30
			else if($format == 'go')
31
				$multiple = 1073741824;
32
			if($convert)
33
				return $input * $multiple;
34
			else
35
				return $input / $multiple;
36
		}
37
	}
38
39
}
40