ErrorNotifierController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 11

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 11
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B Form() 0 39 3
A senderror() 0 6 1
A ShowThankYouNote() 0 4 1
A Link() 0 4 1
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