Completed
Push — master ( f580c3...778708 )
by Peter
06:01
created

StructureChecker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 20
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkEmbeds() 0 5 1
A checkEmbed() 0 11 2
1
<?php
2
3
4
namespace Maslosoft\Mangan\Helpers\Debug;
5
6
7
use function array_walk_recursive;
8
use function get_class;
9
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
10
use Maslosoft\Mangan\Exceptions\StructureException;
11
12
class StructureChecker
13
{
14 158
	public function checkEmbeds($data)
15
	{
16 158
		array_walk_recursive($data, [$this, 'checkEmbed']);
17 157
		return true;
18
	}
19
20 158
	public function checkEmbed($data)
21
	{
22 158
		if ($data instanceof AnnotatedInterface)
23
		{
24
			$params = [
25 1
				get_class($data)
26
			];
27 1
			$message = vsprintf('To store embedded/ref/related model (%s) it must be marked with @Embedded/@Related/@DbRef (Array) annotation', $params);
28 1
			throw new StructureException($message);
29
		}
30
	}
31
}