Conditions | 10 |
Paths | 10 |
Total Lines | 50 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
76 | private function applyWithExtraTermFilters($query) |
||
77 | { |
||
78 | $sng = SiteTree::singleton(); |
||
79 | foreach ($this->params as $name => $val) { |
||
80 | if (empty($val)) { |
||
81 | continue; |
||
82 | } |
||
83 | |||
84 | switch ($name) { |
||
85 | case 'Term': |
||
86 | $query = $query->filterAny([ |
||
87 | 'URLSegment:PartialMatch' => Convert::raw2url($val), |
||
88 | 'Title:PartialMatch' => $val, |
||
89 | 'MenuTitle:PartialMatch' => $val, |
||
90 | 'Content:PartialMatch' => $val |
||
91 | ] + $this->extraTermFilters); // NB: only modified line |
||
92 | break; |
||
93 | |||
94 | case 'URLSegment': |
||
95 | $query = $query->filter([ |
||
96 | 'URLSegment:PartialMatch' => Convert::raw2url($val), |
||
97 | ]); |
||
98 | break; |
||
99 | |||
100 | case 'LastEditedFrom': |
||
101 | $fromDate = DateField::create(null, null, $val); |
||
102 | $query = $query->filter("LastEdited:GreaterThanOrEqual", $fromDate->dataValue().' 00:00:00'); |
||
103 | break; |
||
104 | |||
105 | case 'LastEditedTo': |
||
106 | $toDate = DateField::create(null, null, $val); |
||
107 | $query = $query->filter("LastEdited:LessThanOrEqual", $toDate->dataValue().' 23:59:59'); |
||
108 | break; |
||
109 | |||
110 | case 'ClassName': |
||
111 | if ($val != 'All') { |
||
112 | $query = $query->filter('ClassName', $val); |
||
113 | } |
||
114 | break; |
||
115 | |||
116 | default: |
||
117 | $field = $sng->dbObject($name); |
||
118 | if ($field) { |
||
119 | $filter = $field->defaultSearchFilter(); |
||
120 | $filter->setValue($val); |
||
121 | $query = $query->alterDataQuery([$filter, 'apply']); |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | return $query; |
||
126 | } |
||
128 |