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

NoRFCEmailValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 26 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
    /**
23
     * @param $email
24
     * @param EmailValidation $emailValidation
25
     *
26
     * @return bool
27
     */
28
    public function isValid($email, EmailValidation $emailValidation)
29
    {
30
        $wsp = '[\x20\x09]';
31
        $vchar = '[\x21-\x7e]';
32
        $quoted_pair = "\\\\(?:$vchar|$wsp)";
33
        $qtext = '[\x21\x23-\x5b\x5d-\x7e]';
34
        $qcontent = "(?:$qtext|$quoted_pair)";
35
        $quoted_string = "\"$qcontent*\"";
36
        $atext = '[a-zA-Z0-9!#$%&\'*+\-\/\=?^_`{|}~]';
37
        $dot_atom = "$atext+(?:[.]$atext+)*";
38
        $local_part = "(?:$dot_atom|$quoted_string)";
39
        $domain = $dot_atom;
40
        $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...
41
        $dot_atom_loose = "$atext+(?:[.]|$atext)*";
42
        $local_part_loose = "(?:$dot_atom_loose|$quoted_string)";
43
        $addr_spec_loose = "{$local_part_loose}[@]$domain";
44
45
        // 携帯メールアドレス用に、..や.@を許容する。
46
        $regexp = "/\A{$addr_spec_loose}\z/";
47
48
        if (preg_match($regexp, $email)) {
49
            return true;
50
        }
51
52
        return false;
53
    }
54
}
55