TestIfEmailsAreWorking   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C index() 0 36 7
1
<?php
2
3
/**
4
 *@author nicolaas [at] sunnysideup .co .nz
5
 *
6
 *
7
 **/
8
9
10
class TestIfEmailsAreWorking extends Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    public function index($request)
13
    {
14
        if (!Permission::check("ADMIN")) {
15
            return Security::permissionFailure($this);
16
        }
17
        $email = $request->requestVar($name = "email");
18
        if ($email && Email::validEmailAddress($email)) {
0 ignored issues
show
Deprecated Code introduced by
The method Email::validEmailAddress() has been deprecated with message: 4.0 Use the "is_valid_address" method instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
19
            $number = rand(0, 10000);
20
            $from = Email::getAdminEmail();
0 ignored issues
show
Deprecated Code introduced by
The method Email::getAdminEmail() has been deprecated with message: 4.0 Use the "Email.admin_email" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
21
            $to = $email;
22
            $subject = "test mail ID".$number;
23
            $body = "test mail ID".$number;
24
            $htmlBody = "<h1>test mail ID".$number.'</h1>';
0 ignored issues
show
Unused Code introduced by
$htmlBody 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...
25
            $basicMailOk = @mail($email, $subject, $body);
26
            if ($basicMailOk) {
27
                DB::alteration_message("basic mail (using the PHP mail function)  has been sent with ID: ".$number, "created");
28
            } else {
29
                DB::alteration_message("basic mail (using the PHP mail function) has * NOT * been sent with ID:".$number, "deleted");
30
            }
31
            $e = new Email($from, $to, $subject, $body);
32
            if ($e->send()) {
33
                DB::alteration_message("standard Silverstripe email has been sent with ID: ".$number, "created");
34
            } else {
35
                DB::alteration_message("standard Silverstripe email ***NOT*** has been sent with ID: ".$number, "deleted");
36
            }
37
            //OR
38
            $e = new Email($from, $to, $subject, $body);
39
            if ($e->sendPlain()) {
40
                DB::alteration_message("plain text Silverstripe  email has been sent with ID: ".$number, "created");
41
            } else {
42
                DB::alteration_message("plain text Silverstripe email has ***NOT*** been sent with ID: ".$number, "deleted");
43
            }
44
        } else {
45
            user_error("make sure to add a valid email - current one is '".$email."' (you can add the email like this: ".$request->getURL()."[email protected]", E_USER_WARNING);
46
        }
47
    }
48
}
49