Passed
Push — master ( ddbf8b...086098 )
by Robbie
11:17
created

Handler::securityTokenEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Security\Confirmation;
4
5
use SilverStripe\Core\Injector\Injector;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Control\Director;
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Control\RequestHandler;
10
use SilverStripe\Forms\Form as BaseForm;
11
use SilverStripe\Forms\FieldList;
12
use SilverStripe\Forms\TextField;
13
use SilverStripe\Forms\FormAction;
14
use SilverStripe\Forms\RequiredFields;
15
16
/**
17
 * Confirmation form handler implementation
18
 *
19
 * Handles StorageID identifier in the URL
20
 */
21
class Handler extends RequestHandler
22
{
23
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
24
        '$StorageID!/$Action//$ID/$OtherID' => '$Action',
25
    ];
26
27
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
28
        'index',
29
        'Form'
30
    ];
31
32
    public function Link($action = null)
33
    {
34
        $request = Injector::inst()->get(HTTPRequest::class);
35
        $link = Controller::join_links(Director::baseURL(), $request->getUrl(), $action);
36
37
        $this->extend('updateLink', $link, $action);
38
39
        return $link;
40
    }
41
42
    /**
43
     * URL handler for the log-in screen
44
     *
45
     * @return array
46
     */
47
    public function index()
48
    {
49
        return [
50
            'Title' => _t(__CLASS__.'.FORM_TITLE', 'Confirm potentially dangerous action'),
51
            'Form' => $this->Form()
52
        ];
53
        return $this;
0 ignored issues
show
Unused Code introduced by
return $this is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
54
    }
55
56
    /**
57
     * This method is being used by Form to check whether it needs to use SecurityToken
58
     *
59
     * We always return false here as the confirmation form should decide this on its own
60
     * depending on the Storage data. If we had the original request to
61
     * be POST with its own SecurityID, we don't want to interfre with it. If it's been
62
     * GET request, then it will generate a new SecurityToken
63
     *
64
     * @return bool
65
     */
66
    public function securityTokenEnabled()
67
    {
68
        return false;
69
    }
70
71
    /**
72
     * Returns an instance of Confirmation\Form initialized
73
     * with the proper storage id taken from URL
74
     *
75
     * @return Form
76
     */
77
    public function Form()
78
    {
79
        $storageId = $this->request->param('StorageID');
80
81
        if (!strlen(trim($storageId))) {
82
            $this->httpError(404, "Undefined StorageID");
83
        }
84
85
        return Form::create($storageId, $this, __FUNCTION__);
86
    }
87
}
88