Completed
Push — master ( 898d30...0483c4 )
by Peter
21:25
created

SanitizerAnnotation::init()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 8.9197
cc 4
eloc 11
nc 2
nop 0
crap 4
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\Meta\ManganPropertyAnnotation;
18
19
/**
20
 * Sanitizer. There can be only one sanitizer per field.
21
 * @template Sanitizer(${SanitizerClass})
22
 * @Target('property')
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
class SanitizerAnnotation extends ManganPropertyAnnotation
26
{
27
28
	public $value = null;
29
	public $class;
30
31 41
	public function init()
32
	{
33
		$params = [
34
			'class'
35 41
		];
36 41
		if (is_string($this->value))
37 41
		{
38 35
			$this->class = $this->value;
39 35
		}
40
		else
41
		{
42 8
			foreach (array_keys($this->value) as $key)
43
			{
44 1
				if (!is_numeric($key))
45 1
				{
46 1
					$params[] = $key;
47 1
				}
48 1
			}
49
		}
50 35
		$config = ParamsExpander::expand($this, $params);
51 35
		$this->_entity->sanitizer = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type array<integer,*> is incompatible with the declared type string of property $sanitizer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52 35
	}
53
54
}
55