FormFieldExplanation::getFrontEndFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 *@author nicolaas[at]sunnysideup.co.nz
5
 *@description contains a list of form field and their explantions
6
 *
7
 **/
8
9
10
class FormFieldExplanation extends DataObject
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...
11
{
12
    public static $db = array(
13
        "Name" => "Varchar(255)",
14
        "Title" => "Varchar(255)",
15
        "Explanation" => "Varchar(255)",
16
        "AlternativeFieldLabel" => "Varchar(100)",
17
        "CustomErrorMessage" => "Varchar(100)",
18
        "CustomErrorMessageAdditional" => "Varchar(200)"
19
    );
20
21
    public static $has_one = array(
22
        "Parent" => "SiteTree"
23
    );
24
25
    public static $indexes = array(
26
        "Name" => true
27
    );
28
29
    public static $searchable_fields = array(
30
        "Title" => "PartialMatch"
31
    );
32
33
    public static $field_labels = array(
34
        "Name" => "Field Name",
35
        "Title" => "Label",
36
        "Explanation" => "Explanation",
37
        "AlternativeFieldLabel" => "Alternative Field Label (if any - replaces standard field label)",
38
        "CustomErrorMessage" => "Custom Error Message, shown when field is not entered",
39
        "CustomErrorMessageAdditional" => "Additional (sub-heading) Custom Error Message, shown when field is not entered"
40
41
    );
42
    public static $summary_fields = array(
43
        "Title" => "Title"
44
    );
45
46 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $fields = parent::getCMSFields();
49
        $fields->removeByName("ParentID");
50
        $fields->removeByName("Name");
51
        $fields->replaceField("Title", new LiteralField("Title", "<h3>Edit the details for ".$this->Title."</h3>"));
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<FormFieldExplanation>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
        return $fields;
53
    }
54
55 View Code Duplication
    public function getFrontEndFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $fields = parent::getFrontEndFields();
58
        $fields->removeByName("ParentID");
59
        $fields->removeByName("Name");
60
        $fields->replaceField("Title", new LiteralField("Title", "<h3>Edit the details for ".$this->Title."</h3>"));
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<FormFieldExplanation>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
        return $fields;
62
    }
63
64
    public static $singular_name = "Form Field Explanation";
65
66
    public static $plural_name = "Form Field Explanations";
67
}
68