Completed
Push — master ( abe239...75f371 )
by Nicolaas
02:06
created

TypographyTestPage_Controller::get_css_folder()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 4
nop 0
1
<?php
2
3
/**
4
 * Add a page to your site that allows you to view all the html that can be used in the typography section - if applied correctly.
5
 * TO DO: add a testing sheet with a list of checks to be made (e.g. italics, bold, paragraphy) - done YES / NO, a date and a person who checked it (member).
6
 */
7
8
class TypographyTestPage_Controller extends Page_Controller
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...
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private static $include_first_heading_in_test_copy = false;
0 ignored issues
show
Unused Code introduced by
The property $include_first_heading_in_test_copy 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...
15
16
    /**
17
     * @var string
18
     */
19
    private static $css_folder = '';
0 ignored issues
show
Unused Code introduced by
The property $css_folder 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...
20
21
    /**
22
     * use this to set up alternative form
23
     * formats
24
     * @var string
25
     */
26
    private static $form_class_name = "Form";
0 ignored issues
show
Unused Code introduced by
The property $form_class_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...
27
28
    public static function get_css_folder()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
29
    {
30
        if (Config::inst()->get("TypographyTestPage_Controller", "css_folder")) {
31
            $folder = Config::inst()->get("TypographyTestPage_Controller", "css_folder");
32
        } else {
33
            $folder = "themes/".SSViewer::current_theme()."/css/";
0 ignored issues
show
Deprecated Code introduced by
The method SSViewer::current_theme() has been deprecated with message: 4.0 Use the "SSViewer.theme" config setting instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
34
        }
35
        $fullFolder = Director::baseFolder().'/'.$folder;
36
        if (!file_exists($fullFolder)) {
37
            user_error("could not find the default CSS folder $fullFolder");
38
            $folder = '';
39
        }
40
        return $folder;
41
    }
42
43
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions 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...
44
        "colours" => "ADMIN",
45
        "replacecolours" => "ADMIN"
46
    );
47
48
    public function init()
49
    {
50
        parent::init();
51
        Page_Controller::init();
52
    }
53
54
    public function index()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
55
    {
56
        $this->Content = $this->typographyhtml();
57
        $this->Title = 'Typography Test Page';
58
        return $this->renderWith('Page');
59
    }
60
61
    public function ShowFirstHeading()
62
    {
63
        return Config::inst()->get("TypographyTestPage_Controller", "include_first_heading_in_test_copy");
64
    }
65
66
    public function colours()
67
    {
68
        $baseFolder = Director::baseFolder();
69
        require($baseFolder.'/typography/thirdparty/colourchart/csscolorchart.php');
70
        $cssPath = array($baseFolder.'/themes/', $baseFolder.$this->project()."css/");
71
        echo '<h1>CSS colors found in: ' .
72
            (is_array($cssPath)?implode($cssPath, ', '):$cssPath) . '</h1>';
73
        $themes = new CssColorChart();
74
        $colourList = $themes->listColors($cssPath);
75
        $html = DBField::create_field("HTMLText", $colourList);
76
        echo $html;
77
    }
78
79
    public function Form()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
80
    {
81
        $array = array();
82
        $array[] = "green";
83
        $array[] = "yellow";
84
        $array[] = "blue";
85
        $array[] = "pink";
86
        $array[] = "orange";
87
        $errorField0 = new TextField($name = "ErrorField0", $title = "Text Field Example 1");
88
        $errorField0->setError("message shown when something is good", "good");
89
        $errorField1 = new TextField($name = "ErrorField1", $title = "Text Field Example 2");
90
        $errorField1->setError("message shown when something is bad", "bad");
91
        $errorField2 = new TextField($name = "ErrorField2", $title = "Text Field Example 3");
92
        $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...
93
        $errorField3 = new TextField($name = "ErrorField3", $title = "Text Field Example 4");
94
        $errorField3->setError("there is an error", "required");
95
        $errorField4 = new TextField($name = "ErrorField4", $title = "Text Field Example 5");
96
        $errorField4->setCustomValidationMessage("custom validation error");
97
        $rightTitle = new TextField($name = "RightTitleField", $title = "Left Title is Default");
98
        $rightTitle->setRightTitle("right title here");
99
        $readonlyField = new ReadOnlyField($name = "ReadOnlyField", $title = "ReadOnlyField");
100
        $readonlyField->setValue("read only value");
101
        $groupedDropdownField = new GroupedDropdownField(
102
             $name = "dropdown",
103
             $title = "Simple Grouped Dropdown",
104
             $source = array(
105
                    "primary" => array(
106
                            "1" => "Green",
107
                            "2" => "Red",
108
                            "3" => "Blue",
109
                            "4" => "Orange"
110
                    ),
111
                    "secondary" => array(
112
                            "11" => "Light Blue",
113
                            "12" => "Dark Brown",
114
                            "13" => "Pinkish Red"
115
                    )
116
             )
117
        );
118
        $formClassName = Config::inst()->get("TypographyTestPage_Controller", "form_class_name");
119
        $form = $formClassName::create(
120
            $controller = $this,
121
            $name = "TestForm",
122
            $fields = new FieldList(
123
                // List the your fields here
124
                new HeaderField($name = "HeaderField1", $title = "Default Header Field"),
125
                new LiteralField($name = "LiteralField", "<p>NOTE: All fields up to EmailField are required and should be marked as such</p>"),
126
                new TextField($name = "TextField1", $title = "Text Field Example 1"),
127
                new TextField($name = "TextField2", $title = "Text Field Example 2"),
128
                new TextField($name = "TextField3", $title = "Text Field Example 3"),
129
                new TextField($name = "TextField4", $title = ""),
130
                new HeaderField($name = "HeaderField2a", $title = "Error Messages", 2),
131
                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>'),
132
                $errorField0,
133
                $errorField1,
134
                $errorField2,
135
                $errorField3,
136
                $errorField4,
137
                new HeaderField($name = "HeaderField2b", $title = "Field with right title", 2),
138
                $rightTitle,
139
                $textAreaField = new TextareaField($name = "TextareaField", $title = "Textarea Field"),
140
                new EmailField("EmailField", "Email address"),
141
                new HeaderField($name = "HeaderField2c", $title = "HeaderField Level 2", 2),
142
                new DropdownField($name = "DropdownField", $title = "Dropdown Field", array( 0 => "-- please select --", 1 => "test AAAA", 2 => "test BBBB")),
143
                new OptionsetField($name = "OptionsetField", $title = "Optionset Field", $array),
144
                new CheckboxSetField($name = "CheckboxSetField", $title = "Checkbox Set Field", $array),
145
                new CurrencyField($name = "CurrencyField", $title = "Bling bling"),
146
                new HeaderField($name = "HeaderField3", $title = "Other Fields", 3),
147
                new NumericField($name = "NumericField", $title = "Numeric Field "),
148
                new DateField($name = "DateField", $title = "Date Field"),
149
                new DateField($name = "DateTimeField", $title = "Date and Time Field"),
150
                new FileField($name = "FileField", $title = "File Field"),
151
                new ConfirmedPasswordField($name = "ConfirmPasswordField", $title = "Password"),
152
                new CheckboxField($name = "CheckboxField", $title = "Checkbox Field"),
153
                $groupedDropdownField,
154
                new HeaderField($name = "HeaderField4", $title = "Read-only Field", 3),
155
                $readonlyField
156
            ),
157
            $actions = new FieldList(
158
                    // List the action buttons here
159
                    new FormAction("signup", "Sign up")
160
            ),
161
            $requiredFields = new RequiredFields(
162
                "TextField1", "TextField2", "TextField3", "ErrorField1", "ErrorField2", "EmailField", "TextField3", "RightTitleField", "CheckboxField", "CheckboxSetField"
163
            )
164
        );
165
        $textAreaField->setColumns(7);
166
        $form->setMessage("warning message", "warning");
167
        return $form;
168
    }
169
170
    public function TestForm($data)
171
    {
172
        $this->redirectBack();
173
    }
174
175
    protected function typographyhtml()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
176
    {
177
        return $this->renderWith('TypographySample');
178
    }
179
180
    public function RandomLinkExternal()
181
    {
182
        return "http://www.google.com/?q=".rand(0, 100000);
183
    }
184
185
    public function RandomLinkInternal()
186
    {
187
        return "/?q=".rand(0, 100000);
188
    }
189
190
    public function SiteColours()
191
    {
192
        if ($folder = TypographyTestPage_Controller::get_css_folder()) {
193
            Requirements::themedCSS("CssColorChart", "typography");
194
            //Requirements::javascript("typography/javascript/CssColorChart.js");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
195
            $cssColorChart = new CssColorChart();
196
            return $cssColorChart->listColors(Director::baseFolder()."/".$folder);
197
        }
198
    }
199
200
    public function replacecolours()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
201
    {
202
        if ($folder = Config::inst()->get("TypographyTestPage_Controller", "css_folder")) {
0 ignored issues
show
Unused Code introduced by
$folder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
203
            require_once(Director::baseFolder()."/typography/thirdparty/csscolorchart.php");
204
            $cssColorChart = new CssColorChart();
205
            return $cssColorChart->replaceColours(Director::baseFolder()."/".Config::inst()->get("TypographyTestPage_Controller", "css_folder"));
0 ignored issues
show
Bug introduced by
The method replaceColours() does not seem to exist on object<CssColorChart>.

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...
206
        }
207
        return "no folder specified, use TypographyTestPage_Controller::set_css_folder()";
208
    }
209
}
210