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

StructureChecker::checkEmbeds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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
}