This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
6 | |||
7 | private static $location_for_scss_file = 'themes/main_mysite/src/variables/_themecustomisation.scss'; |
||
0 ignored issues
–
show
|
|||
8 | |||
9 | private static $singular_name = 'Theme Customisation'; |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | function i18n_singular_name() |
||
0 ignored issues
–
show
|
|||
12 | { |
||
13 | return _t('ThemeCustomiser.SINGULAR_NAME', 'Theme Customisation'); |
||
14 | } |
||
15 | |||
16 | private static $plural_name = 'Theme Customisations'; |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | function i18n_plural_name() |
||
0 ignored issues
–
show
|
|||
19 | { |
||
20 | return _t('ThemeCustomiser.PLURAL_NAME', 'Theme Customisations'); |
||
21 | } |
||
22 | |||
23 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
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
|
|||
37 | 'LargeLogo' => 'Image', |
||
38 | 'SmallLogo' => 'Image' |
||
39 | ]; |
||
40 | |||
41 | private static $summary_fields = [ |
||
0 ignored issues
–
show
|
|||
42 | 'LargeLogo.Stripthumbnail' => 'Name' |
||
43 | ]; |
||
44 | |||
45 | private static $field_labels = [ |
||
0 ignored issues
–
show
|
|||
46 | 'MonoFont' => 'Mono spaced font' |
||
47 | ]; |
||
48 | |||
49 | private static $field_labels_right = [ |
||
0 ignored issues
–
show
|
|||
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 ![]() |
|||
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
|
|||
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 ![]() |
|||
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
|
|||
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
|
|||
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 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. ![]() |
|||
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
![]() |
|||
166 | } |
||
167 | |||
168 | } |
||
169 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.