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 | * @authors: Nicolaas [at] Sunny Side Up .co.nz |
||
5 | * @package: ecommerce |
||
6 | * @sub-package: tasks |
||
7 | **/ |
||
8 | class EcommerceTaskReviewSearches extends BuildTask |
||
0 ignored issues
–
show
|
|||
9 | { |
||
10 | /** |
||
11 | * number of days shown. |
||
12 | * |
||
13 | * @int |
||
14 | */ |
||
15 | protected $defaultDays = 100; |
||
16 | |||
17 | /** |
||
18 | * minimum number of searches for |
||
19 | * a particular keyword in order to show it at all. |
||
20 | * |
||
21 | * @int |
||
22 | */ |
||
23 | protected $defaultMinimum = 5; |
||
24 | |||
25 | /** |
||
26 | * show up to XXX days ago. |
||
27 | * |
||
28 | * @int |
||
29 | */ |
||
30 | protected $endingDaysBack = 0; |
||
31 | |||
32 | /** |
||
33 | * Standard (required) SS variable for BuildTasks. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $title = 'Search Statistics'; |
||
38 | |||
39 | /** |
||
40 | * Standard (required) SS variable for BuildTasks. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $description = ' |
||
45 | What did people search for on the website, you can use the days, min and ago GET variables to query different sets.'; |
||
46 | |||
47 | public function run($request) |
||
0 ignored issues
–
show
run uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
Loading history...
|
|||
48 | { |
||
49 | $days = intval($request->getVar('days') - 0); |
||
50 | if (!$days) { |
||
51 | $days = $this->defaultDays; |
||
52 | } |
||
53 | $countMin = intval($request->getVar('min') - 0); |
||
54 | if (!$countMin) { |
||
55 | $countMin = $this->defaultMinimum; |
||
56 | } |
||
57 | $endingDaysBack = intval($request->getVar('ago') - 0); |
||
58 | if (!$endingDaysBack) { |
||
59 | $endingDaysBack = $this->endingDaysBack; |
||
60 | } |
||
61 | $field = EcommerceSearchHistoryFormField::create('stats', $this->title) |
||
62 | ->setNumberOfDays($days) |
||
63 | ->setMinimumCount($countMin) |
||
64 | ->setEndingDaysBack($endingDaysBack); |
||
65 | echo $field->forTemplate(); |
||
66 | $arrayNumberOfDays = array(30, 365); |
||
0 ignored issues
–
show
$arrayNumberOfDays 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
Loading history...
|
|||
67 | |||
68 | $fields = FieldList::create( |
||
69 | HeaderField::create( |
||
70 | 'ShowResultsFor', |
||
71 | 'Show results for ...' |
||
72 | ), |
||
73 | NumericField::create( |
||
74 | 'days', |
||
75 | 'Number of days', |
||
76 | isset($_GET['days']) ? $_GET['days'] : $this->defaultDays |
||
77 | )->setRightTitle('For example, enter 10 to get results from a 10 day period.'), |
||
78 | NumericField::create( |
||
79 | 'ago', |
||
80 | 'Up to how many days go', |
||
81 | isset($_GET['ago']) ? $_GET['ago'] : $this->endingDaysBack |
||
82 | )->setRightTitle('For example, entering 365 days means you get all statistics the specified number of days up to one year ago.'), |
||
83 | NumericField::create( |
||
84 | 'min', |
||
85 | 'Count treshold', |
||
86 | isset($_GET['min']) ? $_GET['min'] : $this->defaultMinimum |
||
87 | )->setRightTitle('Minimum number of searches for it to show up in the statistics. For example, enter five to show only phrases that were searched for at least five times during the specified period.') |
||
88 | ); |
||
89 | $actions = FieldList::create(FormAction::create("run")->setTitle("show results")); |
||
90 | $form = Form::create($this, "SearchFields", $fields, $actions, null); |
||
91 | $form->setAttribute('method', 'get'); |
||
92 | $form->setAttribute('action', $this->Link()); |
||
93 | echo $form->forTemplate(); |
||
94 | echo '<style> |
||
95 | div.field {margin-bottom: 20px;} |
||
96 | .right {font-style:italics; color: #555;} |
||
97 | </style>'; |
||
98 | } |
||
99 | |||
100 | public function Link($action = null) |
||
101 | { |
||
102 | return '/dev/tasks/EcommerceTaskReviewSearches/'; |
||
103 | } |
||
104 | } |
||
105 |
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.