Completed
Push — master ( e9b8ec...943b9d )
by Peter
55:00
created

AnnotationDefaults   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 19 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 21.11.17
6
 * Time: 13:15
7
 */
8
9
namespace Maslosoft\Mangan\Helpers;
10
11
12
use function array_key_exists;
13
use function get_class;
14
use function is_array;
15
use Maslosoft\Addendum\Interfaces\AnnotationInterface;
16
use Maslosoft\Mangan\Mangan;
17
use Maslosoft\Mangan\Meta\ManganAnnotation;
18
19
class AnnotationDefaults
20
{
21
	public static function apply(ManganAnnotation $annotation, $data)
22
	{
23
		$defaults = Mangan::fly()->annotationsDefaults;
24
		$key = get_class($annotation);
25
		if(empty($defaults[$key]))
26
		{
27
			return;
28
		}
29
		assert(is_array($defaults[$key]));
30
		foreach($defaults[$key] as $name => $value)
31
		{
32
			// Don't set values provided from model
33
			if(array_key_exists($name, $data))
34
			{
35
				continue;
36
			}
37
			$annotation->$name = $value;
38
		}
39
	}
40
}