Completed
Push — master ( 59559b...bc4c4e )
by Gabriel
02:27
created

Email::mask()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 13
cts 13
cp 1
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Nip\Utility;
4
5
/**
6
 * Class Email
7
 * @package Nip\Utility
8
 */
9
class Email
10
{
11
    /**
12
     * @param $email
13
     * @return mixed
14
     */
15 5
    public static function mask($email)
16
    {
17 5
        if (strpos($email, '@') === false) {
18 1
            return Str::mask($email, 1);
19
        }
20
21 4
        list ($username, $domain) = explode("@", $email);
22
23 4
        $parts[] = Str::mask($username, 1);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$parts was never initialized. Although not strictly required by PHP, it is generally a good practice to add $parts = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
24 4
        $parts[] = '@';
25
26 4
        $domainParts = explode('.', $domain);
27 4
        $lastPart = array_pop($domainParts);
28 4
        foreach ($domainParts as $part) {
29 3
            $parts[] = Str::mask($part, 1);
30 3
            $parts[] = '.';
31
        }
32 4
        $parts[] = $lastPart;
33 4
        return implode('', $parts);
34
    }
35
}
36