Conditions | 6 |
Paths | 6 |
Total Lines | 57 |
Code Lines | 30 |
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 |
||
31 | public function getResults($forumHolderID, $query, $order, $offset = 0, $limit = 10) |
||
32 | { |
||
33 | $query = $this->cleanQuery($query); |
||
34 | |||
35 | // Default weights put title ahead of content, which effectively |
||
36 | // puts threads ahead of posts. |
||
37 | $fieldWeights = array("Title" => 5, "Content" => 1); |
||
38 | |||
39 | // Work out what sorting method |
||
40 | switch ($order) { |
||
41 | case 'date': |
||
42 | $mode = 'fields'; |
||
43 | |||
44 | $sortarg = array('Created' => 'DESC'); |
||
45 | break; |
||
46 | case 'title': |
||
47 | $mode = 'fields'; |
||
48 | |||
49 | $sortarg = array('Title' => 'ASC'); |
||
50 | break; |
||
51 | default: |
||
52 | // Sort by relevancy, but add the calculated age band, |
||
53 | // which will push up more recent content. |
||
54 | $mode = 'eval'; |
||
55 | $sortarg = "@relevance + _ageband"; |
||
56 | |||
57 | // Downgrade the title weighting, which will give more |
||
58 | // emphasis to age. |
||
59 | $fieldWeights = array("Title" => 1, "Content" => 1); |
||
60 | |||
61 | break; |
||
62 | } |
||
63 | |||
64 | $cachekey = $query.':'.$offset; |
||
65 | if (!isset($this->search_cache[$cachekey])) { |
||
66 | // Determine the classes to search. This always include |
||
67 | // ForumThread and Post, since we decorated them. It also |
||
68 | // includes Forum and Member if they are decorated, as |
||
69 | // appropriate. |
||
70 | $classes = array('ForumThread', 'Post'); |
||
71 | foreach (self::$extra_search_classes as $c) { |
||
72 | if (Object::has_extension($c, 'SphinxSearchable')) { |
||
73 | $classes[] = $c; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $this->search_cache[$cachekey] = SphinxSearch::search($classes, $query, array( |
||
78 | 'start' => $offset, |
||
79 | 'pagesize' => $limit, |
||
80 | 'sortmode' => $mode, |
||
81 | 'sortarg' => $sortarg, |
||
82 | 'field_weights' => $fieldWeights |
||
83 | )); |
||
84 | } |
||
85 | |||
86 | return $this->search_cache[$cachekey]->Matches; |
||
87 | } |
||
88 | |||
153 |
This method has been deprecated.