CheckEmail::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * Copyright (C) 2015 Michael Herold <[email protected]>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace hemio\form;
21
22
/**
23
 * Description of CheckEmail
24
 *
25
 * @author Michael Herold <[email protected]>
26
 */
27
class CheckEmail extends Check {
28
29
    public function __construct($multiple = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $multiple is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
        $this->check = $this;
0 ignored issues
show
Bug introduced by
The property check does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
        $this->id = 'email';
32
        $this->message = _('Not a valid email address');
33
    }
34
35
    public function __invoke($email) {
36
        $exploded = explode('@', $email);
37
        $exploded[] = idn_to_ascii(array_pop($exploded));
38
        $addressAscii = implode('@', $exploded);
39
40
        $valid = filter_var($addressAscii, FILTER_VALIDATE_EMAIL) !== false;
41
42
        return $valid;
43
    }
44
45
}
46