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

StructureChecker::checkEmbed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.9
cc 2
nc 2
nop 1
crap 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
}