Passed
Push — master ( 14ed89...8aec5a )
by Nicolaas
01:56
created

SalesforceSignupForm::setRequiredFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This class can be used by controllers in your project to set up a basic sign up
5
 * form.
6
 *
7
 * You can test it in isolation using the SalesforceExamplesSignupController class.
8
 */
9
10
class SalesforceSignupForm extends Form
11
{
12
13
    private static $allowed_actions = [
1 ignored issue
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
14
        'doSalesforceSignUp' => true
15
    ];
16
17
    private static $based_on_instance_of = 'SalesforceContact';
1 ignored issue
show
introduced by
The private property $based_on_instance_of is not used, and could be removed.
Loading history...
18
19
    /**
20
     * Our constructor only requires the controller and the name of the form
21
     * method. We'll create the fields and actions in here.
22
     *
23
     */
24
    public function __construct($controller, $name)
25
    {
26
        $fields = $this->getBaseFields();
27
28
        $actions = $this->getBaseAction();
29
30
        $required = $this->getBaseRequiredFields();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $required is correct as $this->getBaseRequiredFields() targeting SalesforceSignupForm::getBaseRequiredFields() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
31
32
        // now we create the actual form with our fields and actions defined
33
        // within this class
34
        parent::__construct($controller, $name, $fields, $actions, $required);
35
36
        // any modifications we need to make to the form.
37
        $this->loadDataFrom($_REQUEST);
38
    }
39
40
41
    public function setSigupFields(array $fieldArray)
0 ignored issues
show
Unused Code introduced by
The parameter $fieldArray is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
    public function setSigupFields(/** @scrutinizer ignore-unused */ array $fieldArray)

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

Loading history...
42
    {
43
        $newList = new FieldList();
44
        $oldFields = $this->Fields();
45
        foreach($fieldsArray as $field) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fieldsArray does not exist. Did you maybe mean $fieldArray?
Loading history...
46
            $newField = $oldFields->dataFieldByName($field);
47
            $newList->push($newField);
48
        }
49
50
        $this->setFields($newList);
51
52
        return $this;
53
    }
54
55
    public function setRequiredFields(array $fieldArray)
56
    {
57
        $this->setRequiredFields(new RequiredFields($fieldArray));
0 ignored issues
show
Bug introduced by
new RequiredFields($fieldArray) of type RequiredFields is incompatible with the type array expected by parameter $fieldArray of SalesforceSignupForm::setRequiredFields(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $this->setRequiredFields(/** @scrutinizer ignore-type */ new RequiredFields($fieldArray));
Loading history...
58
59
        return $this;
60
    }
61
62
63
    public function setFormSubmitText(string $label)
64
    {
65
        $newFields = new FieldList(
66
            FormAction::create('doSalesforceSignUp', $label)
67
        );
68
        $this->setActions($newFields);
69
70
        return $this;
71
    }
72
73
    protected function getBaseFields()
74
    {
75
        $newInstanceClassName = Config::inst()->get('SalesforceSignupForm', 'based_on_instance_of');
76
        $newInstance = $newInstanceClassName::create();
77
78
        return $newInstance->getFrontEndFields();
79
80
    }
81
82
    protected function getBaseAction()
83
    {
84
        return new FieldList(
85
            FormAction::create('doSalesforceSignUp', 'Register')
86
        );
87
    }
88
89
    protected function getBaseRequiredFields()
90
    {
91
        new RequiredFields(
92
            [
93
                'FirstName',
94
                'LastName',
95
                'Email',
96
            ]
97
        );
98
    }
99
100
101
    public function doSalesforceSignUp($data, Form $form)
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

101
    public function doSalesforceSignUp($data, /** @scrutinizer ignore-unused */ Form $form)

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

Loading history...
102
    {
103
        MySalesforcePartnerApi::create_contact($data);
0 ignored issues
show
Bug introduced by
The method create_contact() does not exist on MySalesforcePartnerApi. Did you maybe mean create()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
        MySalesforcePartnerApi::/** @scrutinizer ignore-call */ 
104
                                create_contact($data);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
        die('We need the option here to set a redirection link AND/OR provide an AJAX response');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
105
    }
106
107
108
}
109