| Conditions | 4 | 
| Paths | 4 | 
| Total Lines | 70 | 
| Code Lines | 54 | 
| 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  | 
            ||
| 68 | public function handle(ServerRequestInterface $request): ResponseInterface  | 
            ||
| 69 |     { | 
            ||
| 70 |         $tree = $request->getAttribute('tree'); | 
            ||
| 71 | assert($tree instanceof Tree, new InvalidArgumentException());  | 
            ||
| 72 | |||
| 73 | $params = $request->getParsedBody();  | 
            ||
| 74 | $search = $params['search'] ?? '';  | 
            ||
| 75 | $replace = $params['replace'] ?? '';  | 
            ||
| 76 | $context = $params['context'] ?? 'all';  | 
            ||
| 77 | |||
| 78 |         switch ($context) { | 
            ||
| 79 | case 'all':  | 
            ||
| 80 | $records = $this->search_service->searchIndividuals([$tree], [$search]);  | 
            ||
| 81 | $count = $this->replaceRecords($records, $search, $replace);  | 
            ||
| 82 |                 FlashMessages::addMessage(I18N::plural('%s individual has been updated.', '%s individuals have been updated.', $count, I18N::number($count))); | 
            ||
| 83 | |||
| 84 | $records = $this->search_service->searchFamilies([$tree], [$search]);  | 
            ||
| 85 | $count = $this->replaceRecords($records, $search, $replace);  | 
            ||
| 86 |                 FlashMessages::addMessage(I18N::plural('%s family has been updated.', '%s families have been updated.', $count, I18N::number($count))); | 
            ||
| 87 | |||
| 88 | $records = $this->search_service->searchRepositories([$tree], [$search]);  | 
            ||
| 89 | $count = $this->replaceRecords($records, $search, $replace);  | 
            ||
| 90 |                 FlashMessages::addMessage(I18N::plural('%s repository has been updated.', '%s repositories have been updated.', $count, I18N::number($count))); | 
            ||
| 91 | |||
| 92 | $records = $this->search_service->searchSources([$tree], [$search]);  | 
            ||
| 93 | $count = $this->replaceRecords($records, $search, $replace);  | 
            ||
| 94 |                 FlashMessages::addMessage(I18N::plural('%s source has been updated.', '%s sources have been updated.', $count, I18N::number($count))); | 
            ||
| 95 | |||
| 96 | $records = $this->search_service->searchNotes([$tree], [$search]);  | 
            ||
| 97 | $count = $this->replaceRecords($records, $search, $replace);  | 
            ||
| 98 |                 FlashMessages::addMessage(I18N::plural('%s note has been updated.', '%s notes have been updated.', $count, I18N::number($count))); | 
            ||
| 99 | break;  | 
            ||
| 100 | |||
| 101 | case 'name':  | 
            ||
| 102 |                 $adv_name_tags = preg_split("/[\s,;: ]+/", $tree->getPreference('ADVANCED_NAME_FACTS')); | 
            ||
| 103 | $name_tags = array_unique(array_merge([  | 
            ||
| 104 | 'NAME',  | 
            ||
| 105 | 'NPFX',  | 
            ||
| 106 | 'GIVN',  | 
            ||
| 107 | 'SPFX',  | 
            ||
| 108 | 'SURN',  | 
            ||
| 109 | 'NSFX',  | 
            ||
| 110 | '_MARNM',  | 
            ||
| 111 | '_AKA',  | 
            ||
| 112 | ], $adv_name_tags));  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 113 | |||
| 114 | $records = $this->search_service->searchIndividuals([$tree], [$search]);  | 
            ||
| 115 | $count = $this->replaceIndividualNames($records, $search, $replace, $name_tags);  | 
            ||
| 116 |                 FlashMessages::addMessage(I18N::plural('%s individual has been updated.', '%s individuals have been updated.', $count, I18N::number($count))); | 
            ||
| 117 | break;  | 
            ||
| 118 | |||
| 119 | case 'place':  | 
            ||
| 120 | $records = $this->search_service->searchIndividuals([$tree], [$search]);  | 
            ||
| 121 | $count = $this->replacePlaces($records, $search, $replace);  | 
            ||
| 122 |                 FlashMessages::addMessage(I18N::plural('%s individual has been updated.', '%s individuals have been updated.', $count, I18N::number($count))); | 
            ||
| 123 | |||
| 124 | $records = $this->search_service->searchFamilies([$tree], [$search]);  | 
            ||
| 125 | $count = $this->replacePlaces($records, $search, $replace);  | 
            ||
| 126 |                 FlashMessages::addMessage(I18N::plural('%s family has been updated.', '%s families have been updated.', $count, I18N::number($count))); | 
            ||
| 127 | break;  | 
            ||
| 128 | }  | 
            ||
| 129 | |||
| 130 | $url = route(SearchReplacePage::class, [  | 
            ||
| 131 | 'search' => $search,  | 
            ||
| 132 | 'replace' => $replace,  | 
            ||
| 133 | 'context' => $context,  | 
            ||
| 134 | 'tree' => $tree->name(),  | 
            ||
| 135 | ]);  | 
            ||
| 136 | |||
| 137 | return redirect($url);  | 
            ||
| 138 | }  | 
            ||
| 218 |