ResultRow   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 49
rs 10
c 2
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 9 4
A __toArray() 0 2 1
A __get() 0 2 1
A __call() 0 13 3
1
<?php
2
/**
3
 * Class ResultRow
4
 *
5
 * @filesource   ResultRow.php
6
 * @created      28.06.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
/**
16
 * @property mixed[] $array
17
 */
18
class ResultRow extends Result{
19
20
	/**
21
	 * @param string $name
22
	 * @param array  $arguments
23
	 *
24
	 * @return mixed|null
25
	 */
26
	public function __call(string $name, array $arguments){
27
		$value = $this->array[$name] ?? null;
28
29
		if($value !== null){
30
			$func = $arguments[0] ?? null;
31
32
			if(is_callable($func)){
33
				return call_user_func_array($func, [$value]);
0 ignored issues
show
Bug introduced by
It seems like $func can also be of type null; however, parameter $callback of call_user_func_array() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
				return call_user_func_array(/** @scrutinizer ignore-type */ $func, [$value]);
Loading history...
34
			}
35
36
		}
37
38
		return $value;
39
	}
40
41
	/**
42
	 * @inheritdoc
43
	 */
44
	public function __get(string $name){
45
		return $this->array[$name] ?? null;
46
	}
47
48
	/**
49
	 * @inheritdoc
50
	 */
51
	public function __toArray():array{
52
		return $this->__EnumerableToArray();
53
	}
54
55
	/**
56
	 * @inheritdoc
57
	 */
58
	public function offsetSet($offset, $value):void{
59
60
		if($this->sourceEncoding !== null && is_string($value)){
61
			$value = mb_convert_encoding($value, $this->destEncoding, $this->sourceEncoding);
62
		}
63
64
		$offset !== null
65
			? $this->array[$offset] = $value
66
			: $this->array[] = $value;
67
68
	}
69
70
}
71