PropertyHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fillProperties() 0 5 2
A getPropertyArray() 0 14 3
A fillProperty() 0 7 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: brucepc
5
 * Date: 24/02/18
6
 * Time: 12:33
7
 */
8
9
namespace BPCI\SumUp\Traits;
10
11
12
trait PropertyHandler
13
{
14
	/**
15
	 * @param array $data
16
	 */
17 4
    public function fillProperties(array $data): void
18
	{
19 4
		foreach ($data as $p => $v)
20
		{
21 4
			$this->fillProperty($p, $v);
22
		}
23 4
	}
24
25
	/**
26
	 * @param string $property
27
	 * @param mixed $value
28
	 */
29 4
    public function fillProperty(string $property, $value): void
30
	{
31 4
		$property = lcfirst(str_replace('_', '', ucwords($property, '_')));
32 4
		if(property_exists(__CLASS__, $property))
33
		{
34 4
			$method = sprintf('set%s', ucfirst($property));
35 4
			$this->{$method}($value);
36
		}
37 4
	}
38
39
	/**
40
	 * @return array
41
	 */
42 1
    public function getPropertyArray(): array
43
	{
44 1
		$reflection = new \ReflectionClass(__CLASS__);
45 1
		$properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
46 1
		$data = [];
47 1
		foreach($properties as $property){
48 1
			$prop_name = $property->getName();
49 1
			$method = sprintf('get%s', ucfirst($prop_name));
50 1
			$form_name = strtolower(preg_replace('/[A-Z]/', '_$0', $prop_name));
51 1
			if($reflection->hasMethod($method)){
52 1
				$data[$form_name] = $this->{$method}();
53
			}
54
		}
55 1
		return $data;
56
	}
57
58
}
59