Completed
Push — v2 ( d685ea...357b8a )
by Peter
14:20 queued 13s
created

SignalForAnnotation::init()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.2
cc 4
eloc 10
nc 4
nop 0
crap 20
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/signals
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 *
11
 */
12
13
namespace Maslosoft\Signals;
14
15
use Maslosoft\Addendum\Helpers\ParamsExpander;
16
use Maslosoft\Addendum\Utilities\ClassChecker;
17
use Maslosoft\Addendum\Utilities\NameNormalizer;
18
use Maslosoft\Signals\Meta\SignalsAnnotation;
19
20
/**
21
 * SignalForAnnotation
22
 * @template SignalFor(${SlotClass})
23
 * @author Piotr
24
 */
25
class SignalForAnnotation extends SignalsAnnotation
26
{
27
28
	const Ns = __NAMESPACE__;
29
30
	public $value;
31
32
	public function init()
33
	{
34
		$data = ParamsExpander::expand($this, ['class']);
35
		$class = '';
36
		if (isset($data['class']))
37
		{
38
			$class = $data['class'];
39
		}
40
		// Log only, as it is designed as soft-fail
41
		if (empty($class) || !ClassChecker::exists($class))
42
		{
43
			(new Signal)->getLogger()->warning(sprintf('Class not found for @SignalFor on model `%s`', $this->getMeta()->type()->name));
44
			return;
45
		}
46
		NameNormalizer::normalize($class);
47
		$this->getEntity()->signalFor[] = $class;
48
	}
49
50
}
51