GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Email   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 105
rs 10
c 0
b 0
f 0
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A exist() 0 3 1
A hide() 0 25 4
A extract() 0 3 2
A is() 0 3 1
A checkDomain() 0 5 2
A extractAll() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace cse\helpers;
6
7
/**
8
 * Class Email
9
 *
10
 * @package cse\helpers
11
 */
12
class Email
13
{
14
    const UTF8 = 'UTF-8';
15
    const PATTERN = '(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))';
16
17
    /**
18
     * Hide email
19
     *
20
     * @param $email
21
     *
22
     * @return string
23
     */
24
    public static function hide(string $email): string
25
    {
26
        list($name, $domain) = explode('@', $email);
27
28
        $length = mb_strlen($name, self::UTF8);
29
30
        if ($length <= 4) {
31
            // abcd => a***
32
            $result = mb_substr($name, 0, 1, self::UTF8) . str_repeat('*', $length - 1);
33
        } elseif ($length > 4 && $length <= 6) {
34
            // abcdef => a****f
35
            $result = mb_substr($name, 0, 1, self::UTF8)
36
                    . str_repeat('*', $length - 2)
37
                    . mb_substr($name, -1, 1, self::UTF8);
38
        } else {
39
            // abcdefghijk => a****f****k
40
            // abcdefghijkl => a****f*****k
41
            $result = mb_substr($name, 0, 1, self::UTF8)
42
                    . str_repeat('*', (int) floor(($length - 3) / 2))
43
                    . mb_substr($name, (int) ceil(($length - 2) / 2), 1, self::UTF8)
44
                    . str_repeat('*', (int) ceil(($length - 3) / 2))
45
                    . mb_substr($name, -1, 1, self::UTF8);
46
        }
47
48
        return $result . '@' . $domain;
49
    }
50
51
    /**
52
     * Check domain to email
53
     *
54
     * @param string $email
55
     * @param string $domain
56
     *
57
     * @return bool
58
     */
59
    public static function checkDomain(string $email, string $domain): bool
60
    {
61
        $email = trim($email);
62
63
        return strlen($email) == 0 ? false : (preg_match('/^.*@' . $domain . '$/i', $email) === 1);
64
    }
65
66
    /**
67
     * Check email
68
     *
69
     * @param string $email
70
     *
71
     * @return bool
72
     */
73
    public static function is(string $email): bool
74
    {
75
        return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
76
    }
77
78
    /**
79
     * Check email exist to string
80
     *
81
     * @param string $string
82
     * @param string $pattern
83
     *
84
     * @return bool
85
     */
86
    public static function exist(string $string, string $pattern = self::PATTERN): bool
87
    {
88
        return preg_match('/' . $pattern . '/iD', $string) === 1;
89
    }
90
91
    /**
92
     * Extract email to string
93
     *
94
     * @param string $string
95
     * @param string $pattern
96
     *
97
     * @return null|string
98
     */
99
    public static function extract(string $string, string $pattern = self::PATTERN): ?string
100
    {
101
        return preg_match('/' . $pattern . '/iD', $string, $email) === 1 ? $email[0] : null;
102
    }
103
104
    /**
105
     * Extract all email to string
106
     *
107
     * @param string $string
108
     * @param string $pattern
109
     *
110
     * @return null|array
111
     */
112
    public static function extractAll(string $string, string $pattern = self::PATTERN): ?array
113
    {
114
        preg_match_all('/' . $pattern . '/i', $string, $email);
115
116
        return  empty($email[0]) ? null : $email[0];
117
    }
118
}