Completed
Push — dev/store-tests ( 3e9e56...714865 )
by Kiyotaka
05:47
created

NoRFCEmailValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 24 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
/**
20
 * SwiftMailerで使用するEmailのバリデータ.
21
 *
22
 * eccube_rfc_email_checkがfalseの際に, このバリデータが使用される.
23
 * 日本のキャリアメールで使用されていた, ..や.@の形式を許容します.
24
 */
25
class NoRFCEmailValidator extends EmailValidator
26
{
27
    /**
28
     * @param $email
29
     * @param EmailValidation|null $emailValidation
30
     * @return bool
31
     */
32
    public function isValid($email, EmailValidation $emailValidation = null)
33
    {
34
        $wsp = '[\x20\x09]';
35
        $vchar = '[\x21-\x7e]';
36
        $quoted_pair = "\\\\(?:$vchar|$wsp)";
37
        $qtext = '[\x21\x23-\x5b\x5d-\x7e]';
38
        $qcontent = "(?:$qtext|$quoted_pair)";
39
        $quoted_string = "\"$qcontent*\"";
40
        $atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]';
41
        $dot_atom = "$atext+(?:[.]$atext+)*";
42
        $domain = $dot_atom;
43
        $dot_atom_loose = "$atext+(?:[.]|$atext)*";
44
        $local_part_loose = "(?:$dot_atom_loose|$quoted_string)";
45
        $addr_spec_loose = "{$local_part_loose}[@]$domain";
46
47
        // 携帯メールアドレス用に、..や.@を許容する。
48
        $regexp = "/\A{$addr_spec_loose}\z/";
49
50
        if (!preg_match($regexp, $email)) {
51
            return false;
52
        }
53
54
        return true;
55
    }
56
}
57