Completed
Push — master ( 04d955...252859 )
by Antony
19:40
created

ShopEmailPreviewTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 44
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 27 4
1
<?php
2
3
/**
4
 * ShopEmailPreviewTask
5
 *
6
 * @author Anselm Christophersen <[email protected]>
7
 * @date   September 2016
8
 * @package    shop
9
 * @subpackage tasks
10
 */
11
12
/**
13
 * ShopEmailPreviewTask
14
 *
15
 */
16
class ShopEmailPreviewTask extends BuildTask
17
{
18
    protected $title       = "Preview Shop Emails";
19
20
    protected $description = 'Previews shop emails';
21
22
    protected $previewableEmails = array(
23
        'Confirmation',
24
        'Receipt',
25
        'AdminNotification'
26
    );
27
28
29
    /**
30
     * @param SS_HTTPRequest $request
31
     */
32
    public function run($request)
33
    {
34
        $email = $request->remaining();
35
        $params = $request->allParams();
36
        $url = "/dev/{$params['Action']}/{$params['TaskName']}";
37
38
        echo '<h2>Choose Email</h2>';
39
        echo '<ul>';
40
        foreach ($this->previewableEmails as $key => $method) {
41
            echo '<li><a href="' . $url . '/' . $method . '">' . $method . '</a></li>';
42
        }
43
        echo '</ul><hr>';
44
45
        if ($email && in_array($email,$this->previewableEmails)) {
46
            $order = Order::get()->first();
47
            $notifier = OrderEmailNotifier::create($order)
0 ignored issues
show
Documentation introduced by
$order is of type object<DataObject>|null, but the function expects a object<Order>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
                ->setDebugMode(true);
49
            $method = "send$email";
50
            echo $notifier->$method();
51
52
        } else {
53
54
        }
55
        //this is a little hardcore way of ending the party,
56
        //but as it's only used for styling, it works for now
57
        die;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
58
    }
59
}
60