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 |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | /** |
||
3 | *@author: nicolaas[at]sunnysideup.co.nz |
||
4 | *@description: |
||
5 | * a log history and counted history of searches done (e.g. 100 people searched for "sunshine") |
||
6 | * it allows gives the opportunity to link zero or more pages to a particular search phrase |
||
7 | * |
||
8 | * |
||
9 | * |
||
10 | **/ |
||
11 | |||
12 | class SearchHistory extends DataObject |
||
0 ignored issues
–
show
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. ![]() |
|||
13 | { |
||
14 | private static $db = array( |
||
0 ignored issues
–
show
|
|||
15 | "Title" => "Varchar(255)", |
||
16 | "RedirectTo" => "Varchar(255)" |
||
17 | ); |
||
18 | |||
19 | private static $has_many = array( |
||
0 ignored issues
–
show
|
|||
20 | "LogEntries" => "SearchHistoryLog" |
||
21 | ); |
||
22 | |||
23 | private static $many_many = array( |
||
0 ignored issues
–
show
|
|||
24 | "Recommendations" => "SiteTree" |
||
25 | ); |
||
26 | |||
27 | private static $singular_name = 'Search History Phrase'; |
||
0 ignored issues
–
show
|
|||
28 | |||
29 | private static $plural_name = 'Search History Phrases'; |
||
0 ignored issues
–
show
|
|||
30 | |||
31 | private static $default_sort = 'Title'; |
||
0 ignored issues
–
show
|
|||
32 | |||
33 | private static $separator = " | "; |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | private static $minimum_length = 3; |
||
0 ignored issues
–
show
|
|||
36 | |||
37 | private static $number_of_keyword_repeats = 3; |
||
0 ignored issues
–
show
|
|||
38 | |||
39 | private static $searchable_fields = array( |
||
0 ignored issues
–
show
|
|||
40 | "Title", |
||
41 | "RedirectTo" |
||
42 | ); |
||
43 | |||
44 | private static $summary_fields = array( |
||
0 ignored issues
–
show
|
|||
45 | "Title", "RedirectTo" |
||
46 | ); |
||
47 | |||
48 | private static $field_labels = array( |
||
0 ignored issues
–
show
|
|||
49 | "Title" => "Phrase Searched For", |
||
50 | "RedirectTo" => "Redirect To Search Phrase (if any)", |
||
51 | "Recommendations" => "Recommended Pages - must already be part of the natural result set", |
||
52 | ); |
||
53 | |||
54 | public static function add_entry($KeywordString) |
||
55 | { |
||
56 | if ($parent = self::find_entry($KeywordString)) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
57 | //do nothing |
||
58 | } else { |
||
59 | $parent = new SearchHistory(); |
||
60 | $parent->Title = $KeywordString; |
||
0 ignored issues
–
show
The property
Title does not exist on object<SearchHistory> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
61 | $parent->write(); |
||
62 | } |
||
63 | if ($parent) { |
||
64 | $obj = new SearchHistoryLog(); |
||
65 | $obj->SearchedForID = $parent->ID; |
||
0 ignored issues
–
show
The property
SearchedForID does not exist on object<SearchHistoryLog> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
66 | $obj->write(); |
||
67 | return $parent; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | public static function find_entry($KeywordString) |
||
72 | { |
||
73 | $KeywordString = self::clean_keywordstring($KeywordString); |
||
74 | return SearchHistory::get()->filter(array("Title" => $KeywordString))->first(); |
||
75 | } |
||
76 | |||
77 | public static function clean_keywordstring($KeywordString) |
||
78 | { |
||
79 | Convert::raw2sql($KeywordString); |
||
80 | $KeywordString = trim(eregi_replace(" +", " ", $KeywordString)); |
||
81 | return $KeywordString; |
||
82 | } |
||
83 | |||
84 | public function getCMSFields() |
||
85 | { |
||
86 | $fields = parent::getCMSFields(); |
||
87 | $fields->removeByName("Title"); |
||
88 | $fields->addFieldToTab("Root.Main", new HeaderField($name = "TitleHeader", "search for: '".$this->Title."'", 1), "RedirectTo"); |
||
0 ignored issues
–
show
The property
Title does not exist on object<SearchHistory> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
89 | $fields->removeByName("Recommendations"); |
||
90 | if (!$this->RedirectTo) { |
||
0 ignored issues
–
show
The property
RedirectTo does not exist on object<SearchHistory> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
91 | $source = SiteTree::get() |
||
0 ignored issues
–
show
$source 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 ![]() |
|||
92 | ->filter(array("ShowInSearch" => 1)) |
||
93 | ->exclude(array("ClassName" => "SearchPlusPage")); |
||
94 | $sourceArray = $sourc->map()->toArray(); |
||
0 ignored issues
–
show
$sourceArray 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 ![]() |
|||
95 | //$fields->addFieldToTab("Root.Main", new MultiSelectField($name = "Recommendations", $title = "Recommendations", $sourceArray)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% 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. ![]() |
|||
96 | $fields->addFieldToTab("Root.Main", new TreeMultiselectField($name = "Recommendations", $title = "Recommendations", "SiteTree")); |
||
97 | } else { |
||
98 | $fields->addFieldToTab("Root.Main", new LiteralField($name = "Recommendations", '<p>This search phrase cannot have recommendations, because it redirects to <i>'.$this->RedirectTo.'</i></p>')); |
||
0 ignored issues
–
show
The property
RedirectTo does not exist on object<SearchHistory> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
99 | } |
||
100 | $page = SearchPlusPage::get()->first(); |
||
101 | if (!$page) { |
||
102 | user_error("Make sure to create a SearchPlusPage to make proper use of this module", E_USER_NOTICE); |
||
103 | } else { |
||
104 | $fields->addFieldToTab("Root.Main", new LiteralField( |
||
105 | $name = "BackLinks", |
||
106 | $content = |
||
107 | '<p> |
||
108 | Review a graph of all <a href="'.$page->Link().'popularsearchwords/100/10/">Popular Search Phrases</a> OR |
||
109 | <a href="'.$page->Link().'results/?Search='.urlencode($this->Title).'&action_results=Search&redirect=1">try this search</a>. |
||
0 ignored issues
–
show
The property
Title does not exist on object<SearchHistory> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
110 | </p>' |
||
111 | )); |
||
112 | } |
||
113 | return $fields; |
||
114 | } |
||
115 | |||
116 | public function onAfterWrite() |
||
117 | { |
||
118 | $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
||
0 ignored issues
–
show
$bt 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 ![]() |
|||
119 | parent::onAfterWrite(); |
||
120 | //add recommendations that are not actually matching |
||
121 | $combos = $this->Recommendations(); |
||
0 ignored issues
–
show
The method
Recommendations does not exist on object<SearchHistory> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
122 | if ($combos) { |
||
123 | $idArray = array(); |
||
124 | foreach ($combos as $combo) { |
||
125 | $idArray[$combo->SiteTreeID] = $combo->SiteTreeID; |
||
126 | } |
||
127 | if (count($idArray)) { |
||
128 | $pages = SiteTree::get() |
||
129 | ->filter(array("ID" => $idArray)); |
||
130 | if ($pages->count()) { |
||
131 | foreach ($pages as $page) { |
||
132 | $changed = false; |
||
133 | $title = Config::inst()->get("SearchHistory", "seperator").$this->getTitle(); |
||
0 ignored issues
–
show
$title 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 ![]() |
|||
134 | $multipliedTitle = Config::inst()->get("SearchHistory", "seperator").str_repeat($this->getTitle(), Config::inst()->get("SearchHistory", "number_of_keyword_repeats")); |
||
135 | View Code Duplication | if (stripos($page->MetaKeywords." ", $multipliedTitle) === false) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
136 | $page->MetaKeywords. $multipliedTitle; |
||
137 | $changed = true; |
||
138 | } |
||
139 | View Code Duplication | if (stripos($page->MetaKeywords." ", $multipliedTitle) === false) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
140 | $page->MetaKeywords = $page->MetaKeywords. $multipliedTitle; |
||
141 | $changed = true; |
||
142 | } |
||
143 | if ($changed) { |
||
144 | $page->writeToStage('Stage'); |
||
145 | $page->Publish('Stage', 'Live'); |
||
146 | $page->Status = "Published"; |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | //delete useless ones |
||
153 | if (strlen($this->Title) < Config::inst()->get("SearchHistory", "minimum_length")) { |
||
0 ignored issues
–
show
The property
Title does not exist on object<SearchHistory> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
154 | $this->delete(); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | public function requireDefaultRecords() |
||
159 | { |
||
160 | parent::requireDefaultRecords(); |
||
161 | $dos = SearchHistory::get() |
||
162 | ->where("\"Title\" = '' OR \"Title\" IS NULL OR LENGTH(\"Title\") < ".Config::inst()->get("SearchHistory", "minimum_length")); |
||
163 | if ($dos) { |
||
164 | foreach ($dos as $do) { |
||
165 | DB::alteration_message("deleting #".$do->ID." from SearchHistory as it does not have a search phrase", "deleted"); |
||
166 | $do->delete(); |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | |||
172 | |||
173 | |||
174 | class SearchHistoryLog extends DataObject |
||
0 ignored issues
–
show
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. ![]() |
|||
175 | { |
||
176 | private static $has_one = array( |
||
0 ignored issues
–
show
|
|||
177 | "SearchedFor" => "SearchHistory" |
||
178 | ); |
||
179 | |||
180 | private static $singular_name = 'Search History Log Entry'; |
||
0 ignored issues
–
show
|
|||
181 | |||
182 | private static $plural_name = 'Search History Log Entries'; |
||
0 ignored issues
–
show
|
|||
183 | |||
184 | private static $default_sort = 'Created DESC'; |
||
0 ignored issues
–
show
|
|||
185 | } |
||
186 |