| Conditions | 9 | 
| Paths | 256 | 
| Total Lines | 58 | 
| 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  | 
            ||
| 177 | public function changesQuery(ServerRequestInterface $request): Builder  | 
            ||
| 178 |     { | 
            ||
| 179 |         $tree = $request->getAttribute('tree'); | 
            ||
| 180 | assert($tree instanceof Tree, new InvalidArgumentException());  | 
            ||
| 181 | |||
| 182 | $from = $request->getQueryParams()['from'] ?? '';  | 
            ||
| 183 | $to = $request->getQueryParams()['to'] ?? '';  | 
            ||
| 184 | $type = $request->getQueryParams()['type'] ?? '';  | 
            ||
| 185 | $oldged = $request->getQueryParams()['oldged'] ?? '';  | 
            ||
| 186 | $newged = $request->getQueryParams()['newged'] ?? '';  | 
            ||
| 187 | $xref = $request->getQueryParams()['xref'] ?? '';  | 
            ||
| 188 | $username = $request->getQueryParams()['username'] ?? '';  | 
            ||
| 189 | $search = $request->getQueryParams()['search'] ?? [];  | 
            ||
| 190 | $search = $search['value'] ?? '';  | 
            ||
| 191 | |||
| 192 |         $query = DB::table('change') | 
            ||
| 193 |             ->leftJoin('user', 'user.user_id', '=', 'change.user_id') | 
            ||
| 194 |             ->join('gedcom', 'gedcom.gedcom_id', '=', 'change.gedcom_id') | 
            ||
| 195 |             ->select(['change.*', new Expression("COALESCE(user_name, '<none>') AS user_name"), 'gedcom_name']) | 
            ||
| 196 |             ->where('gedcom_name', '=', $tree->name()); | 
            ||
| 197 | |||
| 198 |         if ($search !== '') { | 
            ||
| 199 |             $query->where(static function (Builder $query) use ($search): void { | 
            ||
| 200 | $query  | 
            ||
| 201 |                     ->whereContains('old_gedcom', $search) | 
            ||
| 202 |                     ->whereContains('new_gedcom', $search, 'or'); | 
            ||
| 203 | });  | 
            ||
| 204 | }  | 
            ||
| 205 | |||
| 206 |         if ($from !== '') { | 
            ||
| 207 |             $query->where('change_time', '>=', $from); | 
            ||
| 208 | }  | 
            ||
| 209 | |||
| 210 |         if ($to !== '') { | 
            ||
| 211 | // before end of the day  | 
            ||
| 212 |             $query->where('change_time', '<', Carbon::make($to)->addDay()); | 
            ||
| 213 | }  | 
            ||
| 214 | |||
| 215 |         if ($type !== '') { | 
            ||
| 216 |             $query->where('status', '=', $type); | 
            ||
| 217 | }  | 
            ||
| 218 | |||
| 219 |         if ($oldged !== '') { | 
            ||
| 220 |             $query->whereContains('old_gedcom', $oldged); | 
            ||
| 221 | }  | 
            ||
| 222 |         if ($newged !== '') { | 
            ||
| 223 |             $query->whereContains('new_gedcom', $oldged); | 
            ||
| 224 | }  | 
            ||
| 225 | |||
| 226 |         if ($xref !== '') { | 
            ||
| 227 |             $query->where('xref', '=', $xref); | 
            ||
| 228 | }  | 
            ||
| 229 | |||
| 230 |         if ($username !== '') { | 
            ||
| 231 |             $query->whereContains('user_name', $username); | 
            ||
| 232 | }  | 
            ||
| 233 | |||
| 234 | return $query;  | 
            ||
| 235 | }  | 
            ||
| 237 |