Conditions | 9 |
Paths | 16 |
Total Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
53 | public function run($request) |
||
54 | { |
||
55 | $maxRows = intval(preg_replace('/[^\d.]/', '', $request->getVar('maxrows'))); |
||
56 | $maxRows = intval($maxRows - 0); |
||
57 | if (!$maxRows) { |
||
58 | $maxRows = $this->defaultMaxRows; |
||
59 | } |
||
60 | $days = intval($request->getVar('days') - 0); |
||
61 | if (!$days) { |
||
62 | $days = $this->defaultDays; |
||
63 | } |
||
64 | $countMin = intval($request->getVar('min') - 0); |
||
65 | if (!$countMin) { |
||
66 | $countMin = $this->defaultMinimum; |
||
67 | } |
||
68 | $endingDaysBack = intval($request->getVar('ago') - 0); |
||
69 | if (!$endingDaysBack) { |
||
70 | $endingDaysBack = $this->endingDaysBack; |
||
71 | } |
||
72 | $field = EcommerceSearchHistoryFormField::create('stats', $this->title) |
||
73 | ->setNumberOfDays($days) |
||
74 | ->setMinimumCount($countMin) |
||
75 | ->setMaxRows($maxRows) |
||
76 | ->setEndingDaysBack($endingDaysBack); |
||
77 | echo $field->forTemplate(); |
||
78 | $arrayNumberOfDays = array(30, 365); |
||
|
|||
79 | |||
80 | $fields = FieldList::create( |
||
81 | HeaderField::create( |
||
82 | 'ShowResultsFor', |
||
83 | 'Show results for ...' |
||
84 | ), |
||
85 | NumericField::create( |
||
86 | 'days', |
||
87 | 'Number of days', |
||
88 | isset($_GET['days']) ? $_GET['days'] : $this->defaultDays |
||
89 | )->setRightTitle('For example, enter 10 to get results from a 10 day period.'), |
||
90 | NumericField::create( |
||
91 | 'maxrows', |
||
92 | 'Maximum Number of Rows?', |
||
93 | isset($_GET['maxrows']) ? $_GET['maxrows'] : $this->defaultMaxRows |
||
94 | )->setRightTitle('For example, enter 10 to get results from a 10 day period.'), |
||
95 | NumericField::create( |
||
96 | 'ago', |
||
97 | 'Up to how many days go', |
||
98 | isset($_GET['ago']) ? $_GET['ago'] : $this->endingDaysBack |
||
99 | )->setRightTitle('For example, entering 365 days means you get all statistics the specified number of days up to one year ago.'), |
||
100 | NumericField::create( |
||
101 | 'min', |
||
102 | 'Count treshold', |
||
103 | isset($_GET['min']) ? $_GET['min'] : $this->defaultMinimum |
||
104 | )->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.') |
||
105 | ); |
||
106 | $actions = FieldList::create(FormAction::create("run")->setTitle("show results")); |
||
107 | $form = Form::create($this, "SearchFields", $fields, $actions, null); |
||
108 | $form->setAttribute('method', 'get'); |
||
109 | $form->setAttribute('action', $this->Link()); |
||
110 | echo $form->forTemplate(); |
||
111 | echo '<style> |
||
112 | div.field {margin-bottom: 20px;} |
||
113 | .right {font-style:italics; color: #555;} |
||
114 | </style>'; |
||
115 | } |
||
116 | |||
122 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.