Failed Conditions
Pull Request — 4.0 (#3667)
by k-yamamura
05:55
created

NoRFCEmailValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 25 2
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Validator\EmailValidator;
15
16
use Egulias\EmailValidator\EmailValidator;
17
use Egulias\EmailValidator\Validation\EmailValidation;
18
19
class NoRFCEmailValidator extends EmailValidator
20
{
21
    /**
22
     * @param $email
23
     * @param EmailValidation|null $emailValidation
24
     * @return bool
25
     */
26
    public function isValid($email, EmailValidation $emailValidation = null)
27
    {
28
29
        $wsp = '[\x20\x09]';
30
        $vchar = '[\x21-\x7e]';
31
        $quoted_pair = "\\\\(?:$vchar|$wsp)";
32
        $qtext = '[\x21\x23-\x5b\x5d-\x7e]';
33
        $qcontent = "(?:$qtext|$quoted_pair)";
34
        $quoted_string = "\"$qcontent*\"";
35
        $atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]';
36
        $dot_atom = "$atext+(?:[.]$atext+)*";
37
        $domain = $dot_atom;
38
        $dot_atom_loose = "$atext+(?:[.]|$atext)*";
39
        $local_part_loose = "(?:$dot_atom_loose|$quoted_string)";
40
        $addr_spec_loose = "{$local_part_loose}[@]$domain";
41
42
        // 携帯メールアドレス用に、..や.@を許容する。
43
        $regexp = "/\A{$addr_spec_loose}\z/";
44
45
        if (!preg_match($regexp, $email)) {
46
            return false;
47
        }
48
49
        return true;
50
    }
51
}
52