Matches   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 62
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMatches() 0 4 1
A getMatch() 0 6 2
A equals() 0 14 4
1
<?php
2
3
namespace Openbuildings\Swiftmailer;
4
5
use Swift_Events_SendListener;
6
use Swift_Events_SendEvent;
7
use InvalidArgumentException;
8
9
/**
10
 * @author     Ivan Kerin <[email protected]>
11
 * @copyright  (c) 2015 Clippings Ltd.
12
 * @license    http://spdx.org/licenses/BSD-3-Clause
13
 */
14
class Matches
15
{
16
	const TRUE_EMPTY = true;
17
	const FALSE_EMPTY = false;
18
19
	/**
20
	 * @var MatchInterface[]
21
	 */
22
	private $matches;
23
24
	/**
25
	 * @var boolean
26
	 */
27
	private $emptyValue;
28
29
	/**
30
	 * @param array $list
31
	 */
32 1
	public function __construct(array $list, $emptyValue = false)
33
	{
34 1
		$this->matches = array_map([$this, 'getMatch'], $list);
35 1
		$this->emptyValue = $emptyValue;
36 1
	}
37
38
	/**
39
	 * @return MatchInterface[]
40
	 */
41 1
	public function getMatches()
42
	{
43 1
		return $this->matches;
44
	}
45
46
	/**
47
	 * @param  string $item
48
	 * @return MatchInterface
49
	 */
50 1
	public function getMatch($item)
51
	{
52 1
		return filter_var($item, FILTER_VALIDATE_EMAIL)
53 1
			? new IsEqual($item)
54 1
			: new IsDomainEqual($item);
55
	}
56
57
	/**
58
	 * @param  string $email
59
	 * @return boolean
60
	 */
61 9
	public function equals($email)
62
	{
63 9
		if (empty($this->matches)) {
64 1
			return $this->emptyValue;
65
		}
66
67 8
		foreach ($this->matches as $match) {
68 8
			if ($match->execute($email)) {
69 5
				return true;
70
			}
71
		}
72
73 3
		return false;
74
	}
75
}
76