Completed
Push — master ( 20edd5...7d7f4e )
by smiley
02:32
created

DBResultRow::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Class DBResultRow
4
 *
5
 * @filesource   DBResultRow.php
6
 * @created      23.05.2017
7
 * @package      chillerlan\Database
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Database;
14
15
class DBResultRow extends DBResult{
16
17
	/**
18
	 * @var mixed[]
19
	 */
20
	protected $array = [];
21
22
	/**
23
	 * @param string $name
24
	 * @param array  $arguments
25
	 *
26
	 * @return mixed|null
27
	 */
28
	public function __call(string $name, array $arguments){
29
30
		if(isset($this->array[$name])){
31
32
			if(isset($arguments[0]) && is_callable($arguments[0])){
33
				return call_user_func_array($arguments[0], [$this->array[$name]]);
34
			}
35
36
			return $this->array[$name];
37
		}
38
39
		return null;
40
	}
41
42
	/**
43
	 * @param string $name
44
	 *
45
	 * @return mixed|null
46
	 */
47
	public function __get(string $name) {
48
49
		if(isset($this->array[$name])){
50
			return $this->array[$name];
51
		}
52
53
		return null;
54
	}
55
56
	/**
57
	 * @link http://api.prototypejs.org/language/Enumerable/prototype/toArray/
58
	 *
59
	 * @return array
60
	 */
61
	public function __toArray():array {
62
		return $this->array;
63
	}
64
65
	/**
66
	 * @param int   $offset
67
	 * @param mixed $value
68
	 *
69
	 * @return void
70
	 */
71
	public function offsetSet($offset, $value){
72
73
		$value = !is_null($this->sourceEncoding)
74
			? mb_convert_encoding($value, $this->destEncoding, $this->sourceEncoding)
75
			: $value;
76
77
		if(is_null($offset)){
78
			$this->array[] = $value; // @codeCoverageIgnore
79
		}
80
		else{
81
			$this->array[$offset] = $value;
82
		}
83
84
	}
85
86
}
87