Passed
Push — master ( 10a915...0d23d6 )
by Mattia
08:28 queued 11s
created

UserDataValidator::isValidEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Helpers;
6
7
/**
8
 * Class Date.
9
 */
10
class UserDataValidator
11
{
12
    /**
13
     * Checks if the given string is a valid username.
14
     *
15
     * @param $username
16
     * @return bool
17
     */
18
    public static function isValidUsername(string $username): bool
19
    {
20
        return !(\preg_match('#[\W]+#', $username) === 1);
21
    }
22
23
    /**
24
     * Checks if the given string is a valid UUID.
25
     */
26
    public static function isValidUuid(string $uuid): bool
27
    {
28
        return \preg_match('#[a-f0-9]{32}#i', $uuid) === 1 && \mb_strlen($uuid) === 32;
29
    }
30
31
    /**
32
     * Check if is an email address has invalid characters.
33
     *
34
     * @param string
35
     * @return bool
36
     */
37
    public static function isValidEmail(string $email): bool
38
    {
39
        return \preg_match('#^[a-zA-Z0-9\.\_\%\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,8}$#', $email) === 1;
40
    }
41
}
42