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   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A domain() 0 6 1
A conceal() 0 12 2
A extractEmails() 0 11 2
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