Completed
Push — master ( 882df1...c20ed4 )
by
unknown
01:37
created

EmailAddress::BreakAtSymbol()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
class EmailAddress extends Varchar
4
{
5
    private static $casting = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
6
        'HiddenEmailAddress' => 'HTMLText',
7
    );
8
9
    /**
10
     * Obfuscate all matching emails
11
     *
12
     * @return string
13
     */
14
    public function HiddenEmailAddress()
15
    {
16
        $originalString = $this->value;
17
        $encodedString = '';
18
        $nowCodeString = '';
0 ignored issues
show
Unused Code introduced by
$nowCodeString is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19
        $originalLength = strlen($this->value);
20
        for ($i = 0; $i < $originalLength; ++$i) {
21
            $encodeMode = rand(1, 2); // Switch encoding odd/even
22
            switch ($encodeMode) {
23
                case 1: // Decimal code
24
                    $nowCodeString = '&#'.ord($originalString[$i]).';';
25
                    break;
26
                case 2: // Hexadecimal code
27
                    $nowCodeString = '&#x'.dechex(ord($originalString[$i])).';';
28
                    break;
29
                default:
30
                    return 'ERROR: wrong encoding mode.';
31
            }
32
            $encodedString .= $nowCodeString;
33
        }
34
35
        return $encodedString;
36
    }
37
38
    public function BreakAtSymbol()
39
    {
40
        return str_replace("@", "@<wbr>", $this->value);
41
    }
42
43
44
    /**
45
     * @see DBField::scaffoldFormField()
46
     *
47
     * @param string $title (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $title not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
48
     * @param array $params (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
49
     *
50
     * @return EmailField | NullableField
51
     */
52
    public function scaffoldFormField($title = null, $params = null)
53
    {
54
        if (!$this->nullifyEmpty) {
55
            return NullableField::create(EmailField::create($this->name, $title));
56
        } else {
57
            return EmailField::create($this->name, $title);
58
        }
59
    }
60
}
61