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

DbCommandModel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 19 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