Completed
Push — master ( 0e16bb...b7cc2d )
by Peter
29:55 queued 26:31
created

DbRefAnnotation::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.4286
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link http://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Annotations;
15
16
use Maslosoft\Addendum\Helpers\ParamsExpander;
17
use Maslosoft\Mangan\Decorators\DbRefDecorator;
18
use Maslosoft\Mangan\Decorators\EmbedRefDecorator;
19
use Maslosoft\Mangan\Meta\DbRefMeta;
20
use Maslosoft\Mangan\Meta\ManganPropertyAnnotation;
21
22
/**
23
 * DB reference annotation
24
 * @template DbRef(${class}, ${updatable})
25
 * @Target('property')
26
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
27
 */
28
class DbRefAnnotation extends ManganPropertyAnnotation
29
{
30
31
	public $class;
32
	public $updatable;
33
	public $value;
34
35 4
	public function init()
36
	{
37 4
		$refMeta = $this->_getMeta();
38 4
		$refMeta->single = true;
39 4
		$refMeta->isArray = false;
40 4
		$this->_entity->dbRef = $refMeta;
41 4
		$this->_entity->propagateEvents = true;
42 4
		$this->_entity->owned = true;
43 4
		$this->_entity->decorators[] = DbRefDecorator::class;
44 4
		$this->_entity->decorators[] = EmbedRefDecorator::class;
45 4
	}
46
47 8
	protected function _getMeta()
48
	{
49 8
		$data = ParamsExpander::expand($this, ['class', 'updatable']);
50 8
		$refMeta = new DbRefMeta($data);
51 8
		if (!$refMeta->class)
52 8
		{
53 1
			$refMeta->class = $this->_meta->type()->name;
54 1
		}
55 8
		return $refMeta;
56
	}
57
58
}
59