Passed
Push — developer ( e2dc35...256686 )
by Radosław
18:20
created

MultiEmailField   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 37
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A operatorK() 0 3 1
A operatorC() 0 3 1
A operatorN() 0 3 1
A operatorE() 0 3 1
A getValue() 0 7 3
1
<?php
2
/**
3
 * Multi email condition record field class.
4
 *
5
 * @package UIType
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Mariusz Krzaczkowski <[email protected]>
10
 */
11
12
namespace App\Conditions\RecordFields;
13
14
/**
15
 * Multi email condition record field class.
16
 */
17
class MultiEmailField extends BaseField
18
{
19
	/** @var string Separator. */
20
	protected $separator = ',';
21
22
	/** {@inheritdoc} */
23
	public function getValue(): array
24
	{
25
		$value = [];
26
		if (!empty(parent::getValue()) && \in_array($this->operator, ['e', 'n'])) {
27
			$value = array_map(fn ($email) => $email['e'], \App\Json::decode(parent::getValue()));
28
		}
29
		return $value;
30
	}
31
32
	/** {@inheritdoc} */
33
	public function operatorE(): bool
34
	{
35
		return (bool) array_intersect($this->getValue(), explode($this->separator, $this->value));
36
	}
37
38
	/** {@inheritdoc} */
39
	public function operatorN(): bool
40
	{
41
		return (bool) !array_intersect($this->getValue(), explode($this->separator, $this->value));
42
	}
43
44
	/** {@inheritdoc} */
45
	public function operatorC(): bool
46
	{
47
		return $this->operatorE();
48
	}
49
50
	/** {@inheritdoc} */
51
	public function operatorK(): bool
52
	{
53
		return $this->operatorN();
54
	}
55
}
56