| Conditions | 11 |
| Paths | 48 |
| Total Lines | 55 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 112 | public function getList() |
||
| 113 | { |
||
| 114 | $list = parent::getList(); |
||
| 115 | $query = $this->getSearchData(); |
||
| 116 | $db = DB::get_conn(); |
||
| 117 | |||
| 118 | $start = null; |
||
| 119 | $end = null; |
||
| 120 | $date_filter = null; |
||
| 121 | |||
| 122 | // Ensure that we only show Order objects in the order tab |
||
| 123 | if ($this->modelClass == Estimate::class) { |
||
| 124 | $list = $list |
||
| 125 | ->addFilter(["ClassName" => Estimate::class]); |
||
| 126 | } |
||
| 127 | |||
| 128 | if ($query && array_key_exists("Start", $query)) { |
||
| 129 | $start = new DateTime($query["Start"]); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($query && array_key_exists("End", $query)) { |
||
| 133 | $end = new DateTime($query["End"]); |
||
| 134 | } |
||
| 135 | |||
| 136 | $format = "%Y-%m-%d"; |
||
| 137 | $start_field = $db->formattedDatetimeClause( |
||
| 138 | '"Estimate"."StartDate"', |
||
| 139 | $format |
||
| 140 | ); |
||
| 141 | $end_field = $db->formattedDatetimeClause( |
||
| 142 | '"Estimate"."EndDate"', |
||
| 143 | $format |
||
| 144 | ); |
||
| 145 | |||
| 146 | if ($start && $end) { |
||
| 147 | $date_filter = [ |
||
| 148 | $start_field . ' <= ?' => $end->format("Y-m-d"), |
||
| 149 | $start_field . ' >= ?' => $start->format("Y-m-d"), |
||
| 150 | $end_field . ' >= ?' => $start->format("Y-m-d"), |
||
| 151 | $end_field . ' <= ?' => $end->format("Y-m-d") |
||
| 152 | ]; |
||
| 153 | } elseif ($start && !$end) { |
||
| 154 | $date_filter = [ |
||
| 155 | $start_field . ' <= ?' => $start->format("Y-m-d"), |
||
| 156 | $end_field . ' >= ?' => $start->format("Y-m-d") |
||
| 157 | ]; |
||
| 158 | } |
||
| 159 | |||
| 160 | if ($date_filter) { |
||
| 161 | $list = $list->where($date_filter); |
||
| 162 | } |
||
| 163 | |||
| 164 | $this->extend("updateList", $list); |
||
| 165 | |||
| 166 | return $list; |
||
| 167 | } |
||
| 199 |