TypographyTestForm   C
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 20

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 20
dl 0
loc 103
rs 6.4705
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 100 1
1
<?php
2
3
4
class TypographyTestForm extends Form
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...
5
{
6
    public function __construct($controller, $nameOfForm = 'TestForm')
7
    {
8
        $array = array();
9
        $array[] = "green";
10
        $array[] = "yellow";
11
        $array[] = "blue";
12
        $array[] = "pink";
13
        $array[] = "orange";
14
        $errorField0 = new TextField($name = "ErrorField0", $title = "Text Field Example 1");
15
        $errorField0->setError("message shown when something is good", "good");
16
        $errorField1 = new TextField($name = "ErrorField1", $title = "Text Field Example 2");
17
        $errorField1->setError("message shown when something is bad", "bad");
18
        $errorField2 = new TextField($name = "ErrorField2", $title = "Text Field Example 3");
19
        $errorField2->setCustomValidationMessage("message shown when something is bad", "bad");
0 ignored issues
show
Unused Code introduced by
The call to TextField::setCustomValidationMessage() has too many arguments starting with 'bad'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
20
        $errorField3 = new TextField($name = "ErrorField3", $title = "Text Field Example 4");
21
        $errorField3->setError("there is an error", "required");
22
        $errorField4 = new TextField($name = "ErrorField4", $title = "Text Field Example 5");
23
        $errorField4->setCustomValidationMessage("custom validation error");
24
        $rightTitle = new TextField($name = "RightTitleField", $title = "Left Title is Default");
25
        $rightTitle->setRightTitle("right title here");
26
        $readonlyField = new ReadOnlyField($name = "ReadOnlyField", $title = "ReadOnlyField");
27
        $readonlyField->setValue("read only value");
28
        $groupedDropdownField = new GroupedDropdownField(
29
             $name = "dropdown",
30
             $title = "Simple Grouped Dropdown",
31
             $source = array(
32
                    "primary" => array(
33
                            "1" => "Green",
34
                            "2" => "Red",
35
                            "3" => "Blue",
36
                            "4" => "Orange"
37
                    ),
38
                    "secondary" => array(
39
                            "11" => "Light Blue",
40
                            "12" => "Dark Brown",
41
                            "13" => "Pinkish Red"
42
                    )
43
             )
44
        );
45
        $returnResult = parent::__construct(
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $returnResult is correct as parent::__construct($con...', 'CheckboxSetField')) (which targets Form::__construct()) 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...
46
            $controller,
47
            $nameOfForm,
48
            $fields = new FieldList(
49
                // List the your fields here
50
                new LiteralField($name = "HeaderFieldForForm", $title = '<h1 id="Form">Form Elements</h1>'),
51
                new HeaderField($name = "HeaderField1", $title = "Default Header Field"),
52
                new LiteralField($name = "LiteralField", "<p>NOTE: All fields up to EmailField are required and should be marked as such</p>"),
53
                new TextField($name = "TextField1", $title = "Text Field Example 1"),
54
                new TextField($name = "TextField2", $title = "Text Field Example 2"),
55
                new TextField($name = "TextField3", $title = "Text Field Example 3"),
56
                new TextField($name = "TextField4", $title = ""),
57
                new HeaderField($name = "HeaderField2a", $title = "Error Messages", 2),
58
                new LiteralField($name = "ErrorExplanations", '<p>Below are some error messages, some of them only show up after you have placed your cursor on the field and not completed it (i.e. a reminder to complete the field)</p>'),
59
                $errorField0,
60
                $errorField1,
61
                $errorField2,
62
                $errorField3,
63
                $errorField4,
64
                new HeaderField($name = "HeaderField2b", $title = "Field with right title", 2),
65
                $rightTitle,
66
                $textAreaField = new TextareaField($name = "TextareaField", $title = "Textarea Field"),
67
                new EmailField("EmailField", "Email address"),
68
                new HeaderField($name = "HeaderField2c", $title = "HeaderField Level 2", 2),
69
                new DropdownField($name = "DropdownField", $title = "Dropdown Field", array( 0 => "-- please select --", 1 => "test AAAA", 2 => "test BBBB")),
70
                new OptionsetField($name = "OptionsetField", $title = "Optionset Field", $array),
71
                new CheckboxSetField($name = "CheckboxSetField", $title = "Checkbox Set Field", $array),
72
                new CurrencyField($name = "CurrencyField", $title = "Bling bling"),
73
                new HeaderField($name = "HeaderField3", $title = "Other Fields", 3),
74
                new NumericField($name = "NumericField", $title = "Numeric Field "),
75
                new DateField($name = "DateField", $title = "Date Field"),
76
                new DateField($name = "DateTimeField", $title = "Date and Time Field"),
77
                new FileField($name = "FileField", $title = "File Field"),
78
                new ConfirmedPasswordField($name = "ConfirmPasswordField", $title = "Password"),
79
                new CheckboxField($name = "CheckboxField", $title = "Checkbox Field"),
80
                $groupedDropdownField,
81
                new HeaderField($name = "HeaderField4", $title = "Read-only Field", 3),
82
                $readonlyField
83
            ),
84
            $actions = new FieldList(
85
                    // List the action buttons here
86
                    new FormAction("signup", "Sign up")
87
            ),
88
            $requiredFields = new RequiredFields(
89
                "TextField1",
90
                "TextField2",
91
                "TextField3",
92
                "ErrorField1",
93
                "ErrorField2",
94
                "EmailField",
95
                "TextField3",
96
                "RightTitleField",
97
                "CheckboxField",
98
                "CheckboxSetField"
99
            )
100
        );
101
        $textAreaField->setColumns(7);
102
        $this->setMessage("warning message", "warning");
103
104
        return $returnResult;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
105
    }
106
}
107