Completed
Push — development ( bff125...0f5c1f )
by Fabian
07:22
created

ExcludedEmailDomains::matches()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
/**
3
 * integer_net Magento Module
4
 *
5
 * @category   IntegerNet
6
 * @package    IntegerNet_Anonymizer
7
 * @copyright  Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
8
 * @author     Fabian Schmengler <[email protected]>
9
 */
10
namespace IntegerNet\Anonymizer\Config;
11
12
/**
13
 * Can be used in entity bridge classes to exclude certain email addresses from anonymization
14
 */
15
class ExcludedEmailDomains
16
{
17
    /**
18
     * @var string[]
19
     */
20
    private $domains;
21
    public function __construct(array $domains)
22
    {
23
        $this->domains = $domains;
24
    }
25
26
    public function matches($email)
27
    {
28
        $emailDomain = preg_replace('{.*@(.*)}', '$1', $email);
29
        foreach ($this->domains as $domain) {
30
            if ($emailDomain === $domain) {
31
                return true;
32
            }
33
        }
34
        return false;
35
    }
36
}