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 | * @package webportfolio |
||
6 | * @sub-packages webportfolio |
||
7 | * |
||
8 | * |
||
9 | * |
||
10 | */ |
||
11 | |||
12 | class WebPortfolioPage extends Page |
||
0 ignored issues
–
show
|
|||
13 | { |
||
14 | private static $icon = "webportfolio/images/treeicons/WebPortfolioPage"; |
||
0 ignored issues
–
show
|
|||
15 | |||
16 | private static $db = array( |
||
0 ignored issues
–
show
|
|||
17 | 'HighlightsOnly' => 'Boolean' |
||
18 | ); |
||
19 | |||
20 | private static $has_one = array(); |
||
0 ignored issues
–
show
|
|||
21 | |||
22 | private static $many_many = array( |
||
0 ignored issues
–
show
|
|||
23 | "WebPortfolioItems" => "WebPortfolioItem" |
||
24 | ); |
||
25 | |||
26 | public function getCMSFields() |
||
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 ![]() |
|||
27 | { |
||
28 | $fields = parent::getCMSFields(); |
||
29 | $itemOptionSet = WebPortfolioItem::get(); |
||
30 | $itemOptionSetMap = ($itemOptionSet->count()) ? $itemOptionSet->map('ID', 'Title')->toArray() : array(); |
||
31 | $fields->addFieldsToTab( |
||
32 | "Root.Portfolio", |
||
33 | array( |
||
34 | CheckboxField::create( |
||
35 | 'HighlightsOnly', |
||
36 | 'Highlights Only' |
||
37 | ), |
||
38 | LiteralField::create("UpdatePortfolio", "<h3>Update Portfolio</h3>"), |
||
39 | LiteralField::create("EditPortfolio", "<p><a href=\"/admin/webportfolio\" target=\"_blank\">edit portfolio</a></p>"), |
||
40 | LiteralField::create("RefreshPortfolio", "<p><a href=\"".$this->Link("json/?flush=json")."\" target=\"_blank\">clear portfolio cache</a> (portfolio data is cached to increase loading speed)</p>"), |
||
41 | CheckboxSetField::create( |
||
42 | $name = "WebPortfolioItems", |
||
43 | $title = "Items shown", |
||
44 | $source = $itemOptionSetMap |
||
45 | ) |
||
46 | ) |
||
47 | ); |
||
48 | return $fields; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | class WebPortfolioPage_Controller extends Page_Controller |
||
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. ![]() |
|||
53 | { |
||
54 | private static $allowed_actions = array( |
||
0 ignored issues
–
show
|
|||
55 | "show" |
||
56 | ); |
||
57 | |||
58 | View Code Duplication | public function init() |
|
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. ![]() |
|||
59 | { |
||
60 | parent::init(); |
||
61 | Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js"); |
||
62 | if (class_exists("PrettyPhoto")) { |
||
63 | PrettyPhoto::include_code(); |
||
64 | } else { |
||
65 | user_error("It is recommended that you include the PrettyPhoto Module", E_USER_NOTICE); |
||
66 | } |
||
67 | Requirements::javascript("webportfolio/javascript/webportfolio.js"); |
||
68 | Requirements::themedCSS("WebPortfolioPage", "webportfolio"); |
||
69 | } |
||
70 | |||
71 | protected $IDArray = array(); |
||
72 | protected $hasFilter = false; |
||
73 | protected $currentCode = ""; |
||
74 | protected $currentDescription = ""; |
||
75 | |||
76 | public function index() |
||
77 | { |
||
78 | if (!$this->HighlightsOnly) { |
||
79 | $this->Title .= " - Favourites"; |
||
80 | } |
||
81 | return array(); |
||
82 | } |
||
83 | |||
84 | public function show() |
||
85 | { |
||
86 | $this->hasFilter = true; |
||
87 | $code = Convert::raw2sql($this->request->param("ID")); |
||
88 | if (is_numeric($code) && intval($code) > 0) { |
||
89 | $this->currentCode = $code; |
||
0 ignored issues
–
show
It seems like
$code can also be of type integer or double . However, the property $currentCode is declared as type string . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
90 | $item = WebPortfolioItem::get()->byID(intval($code)); |
||
91 | if ($item) { |
||
92 | $this->IDArray = array($item->ID => $item->ID); |
||
93 | $this->Title .= " - ".$item->getHeadLine(); |
||
94 | $this->currentDescription = $item->Notes; |
||
95 | } |
||
96 | } elseif ($code) { |
||
97 | $this->currentCode = $code; |
||
98 | $obj = WebPortfolioWhatWeDidDescriptor::get()->filter(array("Code" => $code))->first(); |
||
99 | $this->Title .= " - ".$obj->Name; |
||
100 | if ($obj) { |
||
101 | $this->currentDescription = $obj->Description; |
||
102 | $components = $obj->getManyManyComponents('WebPortfolioItem'); |
||
103 | if ($components && $components->count()) { |
||
104 | $this->IDArray = $components->column("ID"); |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | return array(); |
||
109 | } |
||
110 | |||
111 | public function SelectedWebPortfolioItems() |
||
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 ![]() |
|||
112 | { |
||
113 | if ($this->HighlightsOnly) { |
||
114 | return $this->WebPortfolioItems() |
||
115 | ->sort(array("Favourites" => "DESC", "RAND()" => "ASC")); |
||
116 | } |
||
117 | if ($this->hasFilter) { |
||
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. ![]() |
|||
118 | } else { |
||
119 | $components = $this->getManyManyComponents('WebPortfolioItems'); |
||
120 | if ($components && $components->count()) { |
||
121 | $this->IDArray = $components->column("ID"); |
||
122 | } |
||
123 | } |
||
124 | $reset = false; |
||
125 | if (!$this->IDArray) { |
||
126 | $reset = true; |
||
127 | } elseif (!is_array($this->IDArray)) { |
||
128 | $reset = true; |
||
129 | } elseif (!count($this->IDArray)) { |
||
130 | $reset = true; |
||
131 | } |
||
132 | if ($reset) { |
||
133 | $this->IDArray = array(0 => 0); |
||
134 | } |
||
135 | $extraWhere = ""; |
||
136 | if (!$this->hasFilter) { |
||
137 | $extraWhere = " AND \"Favourites\" = 1"; |
||
138 | } |
||
139 | return WebPortfolioItem::get() |
||
140 | ->where("\"WebPortfolioItem\".\"ID\" IN (".implode(",", $this->IDArray).") AND \"WebPortfolioPage_WebPortfolioItems\".\"WebPortfolioPageID\" = ".$this->ID.$extraWhere) |
||
141 | ->sort(array("Favourites" => "DESC", "RAND()" => "ASC")) |
||
142 | ->innerJoin("WebPortfolioPage_WebPortfolioItems", "\"WebPortfolioPage_WebPortfolioItems\".\"WebPortfolioItemID\" = \"WebPortfolioItem\".\"ID\""); |
||
143 | } |
||
144 | |||
145 | public function HasFilter() |
||
146 | { |
||
147 | return $this->hasFilter; |
||
148 | } |
||
149 | |||
150 | public function CurrentDescription() |
||
151 | { |
||
152 | return $this->currentDescription; |
||
153 | } |
||
154 | |||
155 | public function FilterList() |
||
156 | { |
||
157 | if ($this->HighlightsOnly) { |
||
158 | return null; |
||
159 | } |
||
160 | $items = WebPortfolioWhatWeDidDescriptor::get() |
||
161 | ->innerJoin("WebPortfolioItem_WhatWeDid", " \"WebPortfolioItem_WhatWeDid\".\"WebPortfolioWhatWeDidDescriptorID\" = \"WebPortfolioWhatWeDidDescriptor\".\"ID\""); |
||
162 | foreach ($items as $item) { |
||
163 | if ($item->Code == $this->currentCode) { |
||
164 | $item->LinkingMode = "current"; |
||
165 | } else { |
||
166 | $item->LinkingMode = "link"; |
||
167 | } |
||
168 | } |
||
169 | return $items; |
||
170 | } |
||
171 | } |
||
172 |
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.