SignalForAnnotation::init()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL-3.0-only, proprietary` license[s].
5
 *
6
 * @package maslosoft/signals
7
 * @license AGPL-3.0-only, proprietary
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/signals/
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\Helpers\ExceptionFormatter;
19
use Maslosoft\Signals\Meta\SignalsAnnotation;
20
use UnexpectedValueException;
21
22
/**
23
 * SignalForAnnotation
24
 * @template SignalFor(${SlotClass})
25
 * @codeCoverageIgnore
26
 * @author Piotr
27
 */
28
class SignalForAnnotation extends SignalsAnnotation
29
{
30
31
	const Ns = __NAMESPACE__;
32
33
	public $value;
34
35
	public function init()
36
	{
37
		$data = ParamsExpander::expand($this, ['class']);
38
		$class = '';
39
		if (isset($data['class']))
40
		{
41
			$class = $data['class'];
42
		}
43
		if (empty($class) || !ClassChecker::exists($class))
44
		{
45
			$msg = ExceptionFormatter::formatForAnnotation($this, $class);
46
			throw new UnexpectedValueException($msg);
47
		}
48
		NameNormalizer::normalize($class);
49
		$this->getEntity()->signalFor[] = $class;
50
	}
51
52
}
53