Completed
Push — master ( 3aa853...a4d8e0 )
by Nicolaas
01:29
created

TypographyTestPage_Controller::Form()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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
            @mkdir($fullFolder);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
38
            //user_error("could not find the default CSS folder $fullFolder");
39
            $folder = '';
40
        }
41
        return $folder;
42
    }
43
44
    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...
45
        "colours" => "ADMIN",
46
        "replacecolours" => "ADMIN"
47
    );
48
49
    public function init()
50
    {
51
        parent::init();
52
        Page_Controller::init();
53
    }
54
55
    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...
56
    {
57
        $this->Content = $this->typographyhtml();
58
        $this->Title = 'Typography Test Page';
59
        return $this->renderWith('Page');
60
    }
61
62
    public function ShowFirstHeading()
63
    {
64
        return Config::inst()->get("TypographyTestPage_Controller", "include_first_heading_in_test_copy");
65
    }
66
67
    public function colours()
68
    {
69
        $baseFolder = Director::baseFolder();
70
        require($baseFolder.'/typography/thirdparty/colourchart/csscolorchart.php');
71
        $cssPath = array($baseFolder.'/themes/', $baseFolder.$this->project()."css/");
72
        echo '<h1>CSS colors found in: ' .
73
            (is_array($cssPath)?implode($cssPath, ', '):$cssPath) . '</h1>';
74
        $themes = new CssColorChart();
75
        $colourList = $themes->listColors($cssPath);
76
        $html = DBField::create_field("HTMLText", $colourList);
77
        echo $html;
78
    }
79
80
    public function Form()
81
    {
82
        return TypographyTestForm::create($this, 'TestForm');
83
    }
84
85
    public function TestForm($data)
86
    {
87
        $this->redirectBack();
88
    }
89
90
    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...
91
    {
92
        return $this->renderWith('TypographySample');
93
    }
94
95
    public function RandomLinkExternal()
96
    {
97
        return "http://www.google.com/?q=".rand(0, 100000);
98
    }
99
100
    public function RandomLinkInternal()
101
    {
102
        return "/?q=".rand(0, 100000);
103
    }
104
105
    public function SiteColours()
106
    {
107
        if ($folder = TypographyTestPage_Controller::get_css_folder()) {
108
            Requirements::themedCSS("CssColorChart", "typography");
109
            //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...
110
            $cssColorChart = new CssColorChart();
111
            return $cssColorChart->listColors(Director::baseFolder()."/".$folder);
112
        }
113
    }
114
115
    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...
116
    {
117
        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...
118
            require_once(Director::baseFolder()."/typography/thirdparty/csscolorchart.php");
119
            $cssColorChart = new CssColorChart();
120
            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...
121
        }
122
        return "no folder specified, use TypographyTestPage_Controller::set_css_folder()";
123
    }
124
}
125