SlotForAnnotation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 17 4
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
 * SlotForAnnotation
24
 * @template SlotFor(${SignalClass})
25
 * @codeCoverageIgnore
26
 * @author Piotr
27
 */
28
class SlotForAnnotation 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
44
		if (empty($class) || !ClassChecker::exists($class))
45
		{
46
			$msg = ExceptionFormatter::formatForAnnotation($this, $class);
47
			throw new UnexpectedValueException($msg);
48
		}
49
		NameNormalizer::normalize($class);
50
		$this->getEntity()->slotFor[] = $class;
51
	}
52
53
}
54