Passed
Push — master ( e1bc3e...2c9d90 )
by Robbie
02:54 queued 01:10
created

ElementForm::Link()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\ElementalUserForms\Model;
4
5
use SilverStripe\UserForms\Control\UserDefinedFormController;
6
use SilverStripe\UserForms\UserForm;
7
use SilverStripe\Control\Controller;
8
use DNADesign\Elemental\Models\BaseElement;
9
use DNADesign\ElementalUserForms\Control\ElementFormController;
10
11
class ElementForm extends BaseElement
12
{
13
    use UserForm;
14
15
    /**
16
     * @var string
17
     */
18
    private static $table_name = 'ElementForm';
0 ignored issues
show
Unused Code introduced by
The property $table_name 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...
19
20
    /**
21
     * @var string
22
     */
23
    private static $title = 'Form';
0 ignored issues
show
Unused Code introduced by
The property $title 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...
24
25
    /**
26
     * @var string
27
     */
28
    private static $icon = 'dnadesign/silverstripe-elemental-userforms:images/form.svg';
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
29
30
    /**
31
     * @var string
32
     */
33
    private static $controller_class = ElementFormController::class;
0 ignored issues
show
Unused Code introduced by
The property $controller_class 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...
34
35
    /**
36
     * @return UserForm
37
     */
38
    public function ElementForm()
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
39
    {
40
        $controller = new UserDefinedFormController($this);
41
        $current = Controller::curr();
42
43
        if ($current && $current->getAction() == 'finished') {
44
            return $controller->renderWith(UserDefinedFormController::class .'_ReceivedFormSubmission');
45
        }
46
47
        $form = $controller->Form();
48
        $form->setFormAction(
49
            Controller::join_links(
50
                $current->Link(),
51
                'element',
52
                $this->owner->ID,
0 ignored issues
show
Bug Best Practice introduced by
The property owner does not exist on DNADesign\ElementalUserForms\Model\ElementForm. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
                'Form'
54
            )
55
        );
56
57
        return $form;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $form returns the type SilverStripe\Forms\Form which is incompatible with the documented return type SilverStripe\UserForms\UserForm.
Loading history...
58
    }
59
60
    public function Link($action = null)
61
    {
62
        $current = Controller::curr();
63
64
        if ($action === 'finished') {
65
            return Controller::join_links(
66
                $current->Link(),
67
                'finished'
68
            );
69
        }
70
71
        return parent::Link($action);
72
    }
73
}
74