Completed
Push — master ( 62db39...d4511b )
by Ron
03:20
created

FieldValueConverter::convertValue()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
rs 8.8571
cc 5
eloc 7
nc 5
nop 2
1
<?php
2
namespace Kir\MySQL\Builder\Helpers;
3
4
class FieldValueConverter {
5
	/**
6
	 * @param array $row
7
	 * @param array $columnDefinitions
8
	 * @return array
9
	 */
10
	public static function convertValues(array $row, array $columnDefinitions) {
11
		foreach($row as $key => &$value) {
12
			if($value !== null) {
13
				$value = self::convertValue($value, $columnDefinitions[$key]);
14
			}
15
		}
16
		return $row;
17
	}
18
19
	/**
20
	 * @param mixed $value
21
	 * @param string $type
22
	 * @return mixed
23
	 */
24
	private static function convertValue($value, $type) {
25
		switch ($type) {
26
			case 'i':
27
				return $value !== null ? (int) $value : null;
28
			case 'f':
29
				return $value !== null ? (float) $value : null;
30
		}
31
		return $value;
32
	}
33
}
34