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 | *@author nicolaas[at]sunnysideup.co.nz |
|||||||||||
5 | *@description: more details per template. Records are auto-added |
|||||||||||
6 | *@link: http://localhost/www.mysite.co.nz/admin/templates/TemplateoverviewDescription/13/edit |
|||||||||||
7 | **/ |
|||||||||||
8 | ||||||||||||
9 | ||||||||||||
10 | class TemplateoverviewDescription extends DataObject |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
11 | { |
|||||||||||
12 | private static $db = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
13 | "Title" => "Varchar", |
|||||||||||
14 | "Description" => "Text", |
|||||||||||
15 | "ToDoListHyperLink" => "Varchar(255)", |
|||||||||||
16 | "ClassNameLink" => "Varchar(120)" |
|||||||||||
17 | ); |
|||||||||||
18 | ||||||||||||
19 | private static $has_one = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
20 | "Image1" => "Image", |
|||||||||||
21 | "Image2" => "Image", |
|||||||||||
22 | "Image3" => "Image", |
|||||||||||
23 | "Image4" => "Image", |
|||||||||||
24 | "Image5" => "Image", |
|||||||||||
25 | "Image6" => "Image", |
|||||||||||
26 | "Image7" => "Image" |
|||||||||||
27 | ); |
|||||||||||
28 | ||||||||||||
29 | private static $searchable_fields = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
30 | "ClassNameLink" => "PartialMatchFilter" |
|||||||||||
31 | ); |
|||||||||||
32 | ||||||||||||
33 | private static $summary_fields = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
34 | "ClassNameLink", |
|||||||||||
35 | "ToDoListHyperLink" |
|||||||||||
36 | ); |
|||||||||||
37 | ||||||||||||
38 | private static $field_labels = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
39 | "ClassNameLink" => "Page Type Name", |
|||||||||||
40 | "ToDoListHyperLink" => "Link to To Do" |
|||||||||||
41 | ); |
|||||||||||
42 | ||||||||||||
43 | private static $singular_name = 'Template Description'; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
44 | ||||||||||||
45 | private static $plural_name = 'Template Descriptions'; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
46 | ||||||||||||
47 | private static $default_sort = 'ClassNameLink ASC'; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
48 | ||||||||||||
49 | private static $indexes = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
50 | "ClassNameLink" => true |
|||||||||||
51 | ); |
|||||||||||
52 | ||||||||||||
53 | private static $casting = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
54 | "Title" => "Varchar" |
|||||||||||
55 | ); |
|||||||||||
56 | ||||||||||||
57 | /** |
|||||||||||
58 | * Location where we keep the template overview designs. |
|||||||||||
59 | * @var String |
|||||||||||
60 | */ |
|||||||||||
61 | private static $image_folder_name = "templateoverview_advanced/designz"; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
62 | ||||||||||||
63 | /** |
|||||||||||
64 | * Location where we keep the template overview designs. |
|||||||||||
65 | * @var String |
|||||||||||
66 | */ |
|||||||||||
67 | private static $image_source_folder = ""; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
68 | ||||||||||||
69 | public function canCreate($member = null) |
|||||||||||
70 | { |
|||||||||||
71 | return false; |
|||||||||||
72 | } |
|||||||||||
73 | ||||||||||||
74 | public function canDelete($member = null) |
|||||||||||
75 | { |
|||||||||||
76 | return true; |
|||||||||||
77 | } |
|||||||||||
78 | ||||||||||||
79 | public function ClassNameLinkFancy() |
|||||||||||
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 ![]() |
||||||||||||
80 | { |
|||||||||||
81 | return implode(" ", preg_split('/(?<=\\w)(?=[A-Z])/', $this->ClassNameLink)); |
|||||||||||
0 ignored issues
–
show
The property
ClassNameLink does not seem to exist. Did you mean ClassName ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
82 | return preg_replace("/(?<=[^A-Z])([A-Z])/", "$1", $this->ClassNameLink); |
|||||||||||
0 ignored issues
–
show
return preg_replace('/(?... $this->ClassNameLink); does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
||||||||||||
83 | } |
|||||||||||
84 | ||||||||||||
85 | public function Title() |
|||||||||||
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 ![]() |
||||||||||||
86 | { |
|||||||||||
87 | return $this->getTitle(); |
|||||||||||
88 | } |
|||||||||||
89 | public function getTitle() |
|||||||||||
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 ![]() |
||||||||||||
90 | { |
|||||||||||
91 | return $this->ClassNameLinkFancy(); |
|||||||||||
92 | } |
|||||||||||
93 | ||||||||||||
94 | public function ModelAdminLink() |
|||||||||||
95 | { |
|||||||||||
96 | return TemplateoverviewDescriptionModelAdmin::get_full_url_segment().$this->ClassName."/EditForm/field/TemplateoverviewDescription/item/".$this->ID."/edit/"; |
|||||||||||
97 | } |
|||||||||||
98 | ||||||||||||
99 | public function getCMSFields() |
|||||||||||
100 | { |
|||||||||||
101 | $fields = parent::getCMSFields(); |
|||||||||||
102 | $fields->removeByName("ClassNameLink"); |
|||||||||||
103 | $fields->removeByName("Image1"); |
|||||||||||
104 | $fields->removeByName("Image2"); |
|||||||||||
105 | $fields->removeByName("Image3"); |
|||||||||||
106 | $fields->removeByName("Image4"); |
|||||||||||
107 | $fields->removeByName("Image5"); |
|||||||||||
108 | $fields->addFieldToTab("Root.Design", new UploadField("Image1", "Design One")); |
|||||||||||
109 | $fields->addFieldToTab("Root.Design", new UploadField("Image2", "Design Two")); |
|||||||||||
110 | $fields->addFieldToTab("Root.Design", new UploadField("Image6", "Design Three")); |
|||||||||||
111 | $fields->addFieldToTab("Root.Instructions", new UploadField("Image3", "Instructions One")); |
|||||||||||
112 | $fields->addFieldToTab("Root.Instructions", new UploadField("Image4", "Instructions Two")); |
|||||||||||
113 | $fields->addFieldToTab("Root.Instructions", new UploadField("Image5", "Instructions Three")); |
|||||||||||
114 | $fields->addFieldToTab("Root.Instructions", new UploadField("Image7", "Instructions Four")); |
|||||||||||
115 | $fields->addFieldToTab("Root.Main", new HeaderField("ClassNameLinkInfo", "Details for: ".$this->ClassNameLink), "Description"); |
|||||||||||
0 ignored issues
–
show
The property
ClassNameLink does not seem to exist. Did you mean ClassName ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
116 | $fields->addFieldToTab("Root.Main", new LiteralField("BackLink", '<p><a href="'.$page->Link().'#sectionFor-'.$this->ClassNameLink.'">go back to template overview page</a> - dont forget to SAVE FIRST.</p>')); |
|||||||||||
0 ignored issues
–
show
The property
ClassNameLink does not seem to exist. Did you mean ClassName ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
117 | return $fields; |
|||||||||||
118 | } |
|||||||||||
119 | ||||||||||||
120 | public function requireDefaultRecords() |
|||||||||||
121 | { |
|||||||||||
122 | parent::requireDefaultRecords(); |
|||||||||||
123 | $data = ClassInfo::subclassesFor("SiteTree"); |
|||||||||||
124 | $fileList = null; |
|||||||||||
125 | if ($this->Config()->get("image_source_folder")) { |
|||||||||||
126 | $fileList = CMSHelp::get_list_of_files($this->Config()->get("image_source_folder")); |
|||||||||||
127 | if (!is_array($fileList)) { |
|||||||||||
128 | $fileList = null; |
|||||||||||
129 | } elseif (!count($fileList)) { |
|||||||||||
130 | $fileList = null; |
|||||||||||
131 | } |
|||||||||||
132 | } |
|||||||||||
133 | if ($fileList) { |
|||||||||||
134 | $destinationDir = Director::baseFolder()."/assets/".$this->Config()->get("image_folder_name")."/"; |
|||||||||||
135 | $destinationFolder = Folder::find_or_make($this->Config()->get("image_folder_name")); |
|||||||||||
136 | } |
|||||||||||
137 | if ($data) { |
|||||||||||
138 | foreach ($data as $className) { |
|||||||||||
139 | $object = TemplateoverviewDescription::get() |
|||||||||||
140 | ->filter(array("ClassNameLink" => $className))->First(); |
|||||||||||
141 | if (!$object) { |
|||||||||||
142 | $object = new TemplateoverviewDescription(); |
|||||||||||
143 | $object->ClassNameLink = $className; |
|||||||||||
0 ignored issues
–
show
The property
ClassNameLink does not seem to exist. Did you mean ClassName ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
144 | $object->write(); |
|||||||||||
145 | DB::alteration_message("adding template description for $className", "created"); |
|||||||||||
146 | } else { |
|||||||||||
147 | $otherObjects = TemplateoverviewDescription::get() |
|||||||||||
148 | ->filter(array("ClassNameLink" => $className))->exclude(array("ID" => $object->ID)); |
|||||||||||
149 | foreach ($otherObjects as $otherObject) { |
|||||||||||
150 | DB::alteration_message("Deleting superfluous TemplateoverviewDescription with Class Name Link: $className", "deleted"); |
|||||||||||
151 | $otherObject->delete(); |
|||||||||||
152 | } |
|||||||||||
153 | } |
|||||||||||
154 | if ($fileList) { |
|||||||||||
155 | $i = 0; |
|||||||||||
156 | foreach ($fileList as $fileArray) { |
|||||||||||
157 | $explodeByDot = explode(".", $fileArray["FileName"]); |
|||||||||||
158 | if (is_array($explodeByDot) && count($explodeByDot)) { |
|||||||||||
159 | $base = $explodeByDot[0]; |
|||||||||||
160 | $explodeByUnderscore = explode("_", $base); |
|||||||||||
161 | if (is_array($explodeByUnderscore) && count($explodeByUnderscore)) { |
|||||||||||
162 | $base = $explodeByUnderscore[0]; |
|||||||||||
163 | $classNameOptionArray = array($className); |
|||||||||||
164 | for ($j = 0; $j < 10; $j++) { |
|||||||||||
165 | $classNameOptionArray[] = $className.$j; |
|||||||||||
166 | } |
|||||||||||
167 | foreach ($classNameOptionArray as $potentialBase) { |
|||||||||||
168 | if ($base == $potentialBase) { |
|||||||||||
169 | $i++; |
|||||||||||
170 | $filename = "".$this->Config()->get("image_folder_name")."/".$fileArray["FileName"]; |
|||||||||||
171 | if (!file_exists($destinationDir.$fileArray["FileName"])) { |
|||||||||||
172 | copy($fileArray["FullLocation"], $destinationDir.$fileArray["FileName"]); |
|||||||||||
0 ignored issues
–
show
The variable
$destinationDir 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
![]() |
||||||||||||
173 | } |
|||||||||||
174 | $image = $Image::get() |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
175 | ->filter(array("ParentID" => $destinationFolder->ID, "Name" => $fileArray["FileName"]))->First(); |
|||||||||||
0 ignored issues
–
show
The variable
$destinationFolder 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
![]() |
||||||||||||
176 | if (!$image) { |
|||||||||||
177 | $image = new Image(); |
|||||||||||
178 | $image->ParentID = $destinationFolder->ID; |
|||||||||||
179 | $image->Filename = $filename; |
|||||||||||
180 | $image->Name = $fileArray["FileName"]; |
|||||||||||
181 | $image->Title = $fileArray["Title"]; |
|||||||||||
182 | $image->write(); |
|||||||||||
183 | } |
|||||||||||
184 | $fieldName = "Image$i"."ID"; |
|||||||||||
185 | if ($object->$fieldName != $image->ID) { |
|||||||||||
186 | $object->$fieldName = $image->ID; |
|||||||||||
187 | $object->write(); |
|||||||||||
188 | DB::alteration_message("adding image to $className: ".$image->Title." (".$image->Filename.") using $fieldName field.", "created"); |
|||||||||||
189 | } |
|||||||||||
190 | } |
|||||||||||
191 | } |
|||||||||||
192 | } |
|||||||||||
193 | } |
|||||||||||
194 | } |
|||||||||||
195 | } else { |
|||||||||||
196 | DB::alteration_message("no design images found for $className", "deleted"); |
|||||||||||
197 | } |
|||||||||||
198 | } |
|||||||||||
199 | } |
|||||||||||
200 | $helpDirectory = Director::baseFolder()."/".Config::inst()->get("CMSHelp", "help_file_directory_name")."/"; |
|||||||||||
201 | if (!file_exists($helpDirectory)) { |
|||||||||||
202 | mkdir($helpDirectory); |
|||||||||||
203 | } |
|||||||||||
204 | $this->createManifestExcludeFile($helpDirectory); |
|||||||||||
205 | ||||||||||||
206 | $devDirectory = Director::baseFolder()."/".Config::inst()->get("CMSHelp", "dev_file_directory_name")."/"; |
|||||||||||
207 | if (!file_exists($devDirectory)) { |
|||||||||||
208 | mkdir($devDirectory); |
|||||||||||
209 | } |
|||||||||||
210 | $this->createManifestExcludeFile($devDirectory); |
|||||||||||
211 | $this->createHTACCESSDenyAll($devDirectory); |
|||||||||||
212 | } |
|||||||||||
213 | ||||||||||||
214 | View Code Duplication | private function createManifestExcludeFile($dir) |
||||||||||
0 ignored issues
–
show
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. ![]() |
||||||||||||
215 | { |
|||||||||||
216 | $myFile = $dir.'_manifest_exclude'; |
|||||||||||
217 | if (!file_exists($myFile)) { |
|||||||||||
218 | $handle = fopen($myFile, 'w') or user_error('Cannot open file: '.$myFile); |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
219 | $data = ''; |
|||||||||||
220 | fwrite($handle, $data); |
|||||||||||
221 | } |
|||||||||||
222 | } |
|||||||||||
223 | ||||||||||||
224 | View Code Duplication | private function createHTACCESSDenyAll($dir) |
||||||||||
0 ignored issues
–
show
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. ![]() |
||||||||||||
225 | { |
|||||||||||
226 | $myFile = $dir.'.htaccess'; |
|||||||||||
227 | if (!file_exists($myFile)) { |
|||||||||||
228 | $handle = fopen($myFile, 'w') or user_error('Cannot open file: '.$myFile); |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
229 | $data = ' |
|||||||||||
230 | Order Deny,Allow |
|||||||||||
231 | Deny from all |
|||||||||||
232 | '; |
|||||||||||
233 | fwrite($handle, $data); |
|||||||||||
234 | } |
|||||||||||
235 | } |
|||||||||||
236 | ||||||||||||
237 | public function validate() |
|||||||||||
238 | { |
|||||||||||
239 | if ($this->ID) { |
|||||||||||
240 | if ( |
|||||||||||
241 | TemplateoverviewDescription::get() |
|||||||||||
242 | ->filter(array("ClassNameLink" => $this->ClassNameLink)) |
|||||||||||
0 ignored issues
–
show
The property
ClassNameLink does not seem to exist. Did you mean ClassName ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
243 | ->exclude(array("ID" => $this->ID)) |
|||||||||||
244 | ) { |
|||||||||||
245 | return new ValidationResult(false, _t("TemplateoverviewDescription.ALREADYEXISTS", "This template already exists")); |
|||||||||||
246 | } |
|||||||||||
247 | } |
|||||||||||
248 | return new ValidationResult(); |
|||||||||||
249 | } |
|||||||||||
250 | ||||||||||||
251 | public function onBeforeWrite() |
|||||||||||
252 | { |
|||||||||||
253 | parent::onBeforeWrite(); |
|||||||||||
254 | } |
|||||||||||
255 | ||||||||||||
256 | public function forTemplate() |
|||||||||||
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 ![]() |
||||||||||||
257 | { |
|||||||||||
258 | return $this->ClassNameLink; |
|||||||||||
0 ignored issues
–
show
The property
ClassNameLink does not seem to exist. Did you mean ClassName ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
||||||||||||
259 | } |
|||||||||||
260 | } |
|||||||||||
261 |
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.