Conditions | 7 |
Paths | 8 |
Total Lines | 52 |
Code Lines | 41 |
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 |
||
47 | public function run($request) |
||
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); |
||
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 | |||
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.