Passed
Push — developer ( 2839bb...ce8c8e )
by Radosław
22:21
created

MultiDomainField   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

6 Methods

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