ErrorNotifierController::senderror()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/**
4
 *@author nicolaas[at]sunnysideup.co.nz
5
 *
6
 **/
7
8
class ErrorNotifierController 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...
9
{
10
    private static $allowed_actions = 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...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
11
        "senderror" => "ADMIN"
12
    );
13
14
    private static $email_to_send_error_to = '';
0 ignored issues
show
Unused Code introduced by
The property $email_to_send_error_to is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
16
    protected $showThankYouNote = false;
17
18
    public function Form()
19
    {
20
        if ($this->request->requestVar('_REDIRECT_BACK_URL')) {
21
            $url = $this->request->requestVar('_REDIRECT_BACK_URL');
22
        } elseif ($this->request->getHeader('Referer')) {
23
            $url = $this->request->getHeader('Referer');
24
        } else {
25
            $url = Director::baseURL();
26
        }
27
        $folder = Folder::find_or_make("ErrorScreenshots");
28
29
        $whatDidYouTryDoField = new TextareaField('WhatDidYouTryToDo', 'What did you try to do');
30
        $whatDidYouTryDoField->setRows(3);
31
32
        $whatWentWrongField = new TextareaField('WhatWentWrong', 'What went wrong');
33
        $whatWentWrongField->setRows(3);
34
35
        $screenshotField = new FileField(
36
            'Screenshot',
37
            'To take a screenshot press the PRT SCR button on your keyboard, then open MS Word or MS Paint and paste the screenshot. Save the file and then attach (upload) the file here.'
38
        );
39
        $screenshotField->setFolderName($folder->Name);
40
41
        $form = new Form($this, 'Form',
42
            new FieldList(
43
                new TextField('Name'),
44
                new TextField('Email'),
45
                new TextField('URL', 'What is the URL of the page the error occured (this is the address shown in the address bar (e.g. http://www.mysite.com/mypage/with/errors/)', $url),
46
                $whatDidYouTryDoField,
47
                $whatWentWrongField,
48
                $screenshotField
49
            ),
50
            new FieldList(
51
                new FormAction('senderror', 'Submit Error')
52
            ),
53
            new RequiredFields(array("Email", "Name"))
54
        );
55
        return $form;
56
    }
57
58
    public function senderror($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        mail($this->Config()->get("email_to_send_error_to"), "error on ".Director::absoluteURL(), print_r($data, true));
0 ignored issues
show
Bug introduced by
The call to absoluteURL() misses a required argument $url.

This check looks for function calls that miss required arguments.

Loading history...
61
        $this->showThankYouNote = true;
62
        return array();
63
    }
64
65
    public function ShowThankYouNote()
66
    {
67
        return $this->showThankYouNote;
68
    }
69
70
    public function Link($action = "")
0 ignored issues
show
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        return "/error/report/";
73
    }
74
}
75