Failed Conditions
Pull Request — 4.0 (#3667)
by k-yamamura
09:53 queued 03:40
created

NoRFCEmailValidator::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
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 $emailValidation
24
     *
25
     * @return bool
26
     */
27
    public function isValid($email, EmailValidation $emailValidation)
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
        $local_part = "(?:$dot_atom|$quoted_string)";
38
        $domain = $dot_atom;
39
        $addr_spec = "{$local_part}[@]$domain";
0 ignored issues
show
Unused Code introduced by
$addr_spec is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
        $dot_atom_loose = "$atext+(?:[.]|$atext)*";
41
        $local_part_loose = "(?:$dot_atom_loose|$quoted_string)";
42
        $addr_spec_loose = "{$local_part_loose}[@]$domain";
43
44
        // 携帯メールアドレス用に、..や.@を許容する。
45
        $regexp = "/\A{$addr_spec_loose}\z/";
46
47
        if (preg_match($regexp, $email)) {
48
            return true;
49
        }
50
51
        return false;
52
    }
53
}
54