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.

Concealer::extractEmails()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\EmailConcealer;
4
5
class Concealer
6
{
7
    const REGEX = '/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})/i';
8
9
    /** @var string */
10
    protected $domain = 'example.com';
11
12
    public static function create()
13
    {
14
        return new static();
15
    }
16
17
    /**
18
     * @param string $domain
19
     *
20
     * @return $this
21
     */
22
    public function domain(string $domain)
23
    {
24
        $this->domain = $domain;
25
26
        return $this;
27
    }
28
29
    public function conceal(string $string): string
30
    {
31
        $concealedEmails = ConcealedEmailCollection::make($this->domain)->fill(
32
            $this->extractEmails($string)
33
        );
34
35
        foreach ($concealedEmails as $original => $concealed) {
36
            $string = str_replace($original, $concealed, $string);
37
        }
38
39
        return $string;
40
    }
41
42
    protected function extractEmails(string $string): array
43
    {
44
        $matches = [];
45
        preg_match_all(static::REGEX, $string, $matches);
46
47
        if (! $matches) {
48
            return [];
49
        }
50
51
        return $matches[0] ?? [];
52
    }
53
}
54