Completed
Push — master ( 2c5f1b...de26ae )
by Peter
05:39
created

DbCommandModel::toArray()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.2
cc 4
eloc 11
nc 4
nop 1
crap 4
1
<?php
2
3
namespace Maslosoft\Mangan\Model\Command;
4
5
use ReflectionClass;
6
7
/**
8
 * DbModel
9
 *
10
 * @internal This is base class for database commands models
11
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
12
 */
13
abstract class DbCommandModel
14
{
15
16 2
	public function toArray($except = [])
17
	{
18 2
		$result = [];
19 2
		foreach ((new ReflectionClass($this))->getProperties() as $info)
20
		{
21 2
			$name = $info->name;
22 2
			if (in_array($name, $except))
23
			{
24 2
				continue;
25
			}
26 2
			$value = $this->$name;
27 2
			if ($value instanceof self)
28
			{
29 1
				$value = $value->toArray();
30
			}
31 2
			$result[$name] = $value;
32
		}
33 2
		return $result;
34
	}
35
36
}
37