Passed
Push — developer ( b71d85...a26ac2 )
by Radosław
18:42
created

MultiEmailField   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 12
dl 0
loc 46
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A operatorC() 0 3 1
A operatorK() 0 3 1
A getValue() 0 10 3
A operatorE() 0 3 1
A getOperator() 0 3 2
A operatorN() 0 3 1
1
<?php
2
/**
3
 * MultiEmail Query 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    Arkadiusz Adach <[email protected]>
10
 * @author    Radosław Skrzypczak <[email protected]>
11
 */
12
13
namespace App\Conditions\QueryFields;
14
15
/**
16
 * MultiEmail Query Field Class.
17
 */
18
class MultiEmailField extends BaseField
19
{
20
	/** @var string Separator. */
21
	protected $separator = ',';
22
23
	/** {@inheritdoc} */
24
	public function getValue()
25
	{
26
		$valueArray = array_filter(explode($this->separator, $this->value));
27
		if (\in_array($this->operator, ['e', 'n'])) {
28
			foreach ($valueArray as $key => $value) {
29
				$valueArray[$key] = "\"{$value}\"";
30
			}
31
		}
32
33
		return $valueArray;
34
	}
35
36
	/** {@inheritdoc} */
37
	public function getOperator(): string
38
	{
39
		return 'a' === $this->operator ? 'c' : $this->operator;
40
	}
41
42
	/** {@inheritdoc} */
43
	public function operatorE(): array
44
	{
45
		return ['or like', $this->getColumnName(), $this->getValue()];
46
	}
47
48
	/** {@inheritdoc} */
49
	public function operatorN(): array
50
	{
51
		return ['not like', $this->getColumnName(), $this->getValue()];
52
	}
53
54
	/** {@inheritdoc} */
55
	public function operatorC(): array
56
	{
57
		return $this->operatorE();
58
	}
59
60
	/** {@inheritdoc} */
61
	public function operatorK(): array
62
	{
63
		return $this->operatorN();
64
	}
65
}
66