valid-email.php ➔ email()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the php-valid-email library.
5
 *
6
 * (c) Gunter Grodotzki <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace AfriCC\Valid;
13
14
function email($string)
15
{
16
    $pos = strrpos($string, '@');
17
    if ($pos === false) {
18
        return false;
19
    }
20
21
    $ascii_email = substr($string, 0, $pos) . '@' . idn_to_ascii(substr($string, $pos + 1), 0, INTL_IDNA_VARIANT_2003);
22
23
    if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
24
        $flags = FILTER_FLAG_EMAIL_UNICODE;
25
    } else {
26
        $flags = null;
27
    }
28
29
    return (bool) filter_var($ascii_email, FILTER_VALIDATE_EMAIL, $flags);
30
}
31