Passed
Pull Request — developer (#16921)
by Arkadiusz
16:28
created

MultiEmailField::operatorE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
		if (!empty(parent::getValue()) && \in_array($this->operator, ['e', 'n'])) {
26
			return array_map(fn ($email) => $email['e'], \App\Json::decode(parent::getValue()));
27
		}
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 25 is false. This is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
28
	}
29
30
	/** {@inheritdoc} */
31
	public function operatorE(): bool
32
	{
33
		return (bool) array_intersect($this->getValue(),    explode($this->separator, $this->value));
34
	}
35
36
	/** {@inheritdoc} */
37
	public function operatorN(): bool
38
	{
39
		return (bool) !array_intersect($this->getValue(), explode($this->separator, $this->value));
40
	}
41
42
	/** {@inheritdoc} */
43
	public function operatorC(): bool
44
	{
45
		return $this->operatorE();
46
	}
47
48
	/** {@inheritdoc} */
49
	public function operatorK(): bool
50
	{
51
		return $this->operatorN();
52
	}
53
}
54