Issues (39)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/model/ThemeCustomisation.php (25 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
5
class ThemeCustomisation 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...
6
7
    private static $location_for_scss_file = 'themes/main_mysite/src/variables/_themecustomisation.scss';
0 ignored issues
show
The property $location_for_scss_file 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...
8
9
    private static $singular_name = 'Theme Customisation';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $singular_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...
10
11
    function i18n_singular_name()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
    {
13
        return _t('ThemeCustomiser.SINGULAR_NAME', 'Theme Customisation');
14
    }
15
16
    private static $plural_name = 'Theme Customisations';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $plural_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...
17
18
    function i18n_plural_name()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
    {
20
        return _t('ThemeCustomiser.PLURAL_NAME', 'Theme Customisations');
21
    }
22
23
    private static $db = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $db 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...
24
        'BackgroundColour' => 'Color',
25
        'FontColour' => 'Color',
26
        'Accent1Colour' => 'Color',
27
        'Accent2Colour' => 'Color',
28
        'MenuBarBackgroundColour' => 'Color',
29
        'LinkColour' => 'Color',
30
        'ActiveColour' => 'Color',
31
        'HeaderFont' => 'Varchar(50)',
32
        'TextFont' => 'Varchar(50)',
33
        'MonoFont' => 'Varchar(50)'
34
    ];
35
36
    private static $has_one = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $has_one 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...
37
        'LargeLogo' => 'Image',
38
        'SmallLogo' => 'Image'
39
    ];
40
41
    private static $summary_fields = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $summary_fields 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...
42
        'LargeLogo.Stripthumbnail' => 'Name'
43
    ];
44
45
    private static $field_labels = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $field_labels 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...
46
        'MonoFont' => 'Mono spaced font'
47
    ];
48
49
    private static $field_labels_right = [
0 ignored issues
show
The property $field_labels_right 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...
50
        'MonoFont' => 'Font similar to courier with identical width used for each character - great for numbers.'
51
    ];
52
53
54
    public function CMSEditLink()
55
    {
56
        $controller = singleton("ThemeCustomiser");
57
58
        return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/".$this->ID."/edit";
59
    }
60
61
    public function CMSAddLink()
62
    {
63
        $controller = singleton("ThemeCustomiser");
64
65
        return $controller->Link().$this->ClassName."/EditForm/field/".$this->ClassName."/item/new";
66
    }
67
68
    public function getCMSFields()
69
    {
70
        $fields = parent::getCMSFields();
71
72
        $fontList = Injector::inst()->get('GoogleFontProvider')->fullList();
73
        $fontFields = $this->Config()->get('font_fields');
0 ignored issues
show
$fontFields 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...
74
        $labels = $this->FieldLabels();
75
        foreach($this->fontFields() as $fontField) {
76
            $fields->replaceField(
77
                $fontField,
78
                DropdownField::create(
79
                    $fontField,
80
                    $labels[$fontField],
81
                    ['' => '-- select --'] + $fontList
82
                )
83
            );
84
        }
85
        foreach($this->colourFields() as $colourField) {
86
            $fields->replaceField(
87
                $colourField,
88
                ColorField::create(
89
                    $colourField,
90
                    $labels[$colourField]
91
                )
92
            );
93
        }
94
95
        $rightFieldDescriptions = $this->Config()->get('field_labels_right');
96
        foreach($rightFieldDescriptions as $field => $desc) {
97
            $field = $fields->DataFieldByName($field);
98
            if($field) {
99
                $field->setDescription($desc);
100
            }
101
        }
102
103
        return $fields;
104
    }
105
106
    /**
107
     * exports to variable SCSS file ...
108
     */
109
    function exportToThemeSCSS()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
110
    {
111
112
        $location = Director::baseFolder() .'/'. $this->Config()->get('location_for_scss_file');
113
        $data = $this->renderWith('ThemeCustomisationSCSSOutput');
114
        file_put_contents($location, $data);
115
    }
116
117
    /**
118
     * stuff to be inserted into head of html
119
     * - custom css
120
     * - link to google fonts ...
121
     */
122
    function htmlForPageHeader()
0 ignored issues
show
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...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
123
    {
124
        $list = [];
125
        foreach($this->fontFields() as $fontField) {
126
            $list[$this->$fontField] = $this->$fontField;
127
        }
128
        $fontList = Injecton::inst()->get('GoogleFontProvider')->getLink($list);
129
130
        return $fontList;
131
    }
132
133
    function canCreate($member = null)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
134
    {
135
        if(ThemeCustomisation::get()->count()) {
136
            return false;
137
        }
138
139
        return parent::canCreate($member);
140
    }
141
142
    function canDelete($member = null)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
143
    {
144
        return false;
145
    }
146
147
    protected function fontFields()
148
    {
149
        return $this->fieldsPerType('Font');
150
    }
151
152
    protected function colourFields()
153
    {
154
        return $this->fieldsPerType('Colour');
155
    }
156
157
    protected function fieldsPerType($name)
158
    {
159
        $list = $this->Config()->get('db');
160
        foreach($list as $key => $type) {
161
            if(substr($key, strlen($name) * -1) === $name) {
162
                $newList[$key] = $key;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$newList was never initialized. Although not strictly required by PHP, it is generally a good practice to add $newList = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
163
            }
164
        }
165
        return $newList;
0 ignored issues
show
The variable $newList does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
166
    }
167
168
}
169