| Conditions | 13 |
| Paths | 2 |
| Total Lines | 68 |
| Code Lines | 42 |
| 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 |
||
| 25 | public function index(HTTPRequest $request = null) |
||
| 26 | { |
||
| 27 | $request = $this->getRequest(); |
||
| 28 | $Query = $request->getVar('q'); |
||
| 29 | $SearchList = new ArrayList(); |
||
| 30 | if ($Query) { |
||
| 31 | $FullQuery = str_replace(' ', '%', $Query); |
||
| 32 | |||
| 33 | // Search page by title/content |
||
| 34 | $excludedPageClasses = [ |
||
| 35 | ErrorPage::class, |
||
| 36 | ]; |
||
| 37 | $filters = [ |
||
| 38 | "Title:PartialMatch" => $FullQuery, |
||
| 39 | "Content:PartialMatch" => $FullQuery, |
||
| 40 | ]; |
||
| 41 | $Results = SiteTree::get()->filterAny($filters)->exclude('ClassName', $excludedPageClasses); |
||
| 42 | foreach ($Results as $Result) { |
||
| 43 | if ($Result->canView()) { |
||
| 44 | $SearchList->push($Result); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | // Also search DataObjects in sitemap |
||
| 49 | $dataObjects = self::getSearchableDataObjects(); |
||
| 50 | foreach ($dataObjects as $dataObject) { |
||
| 51 | $sng = singleton($dataObject); |
||
| 52 | |||
| 53 | $filters = []; |
||
| 54 | if ($sng->hasMethod('getSearchFilters')) { |
||
| 55 | // Use dedicated filters |
||
| 56 | $filters = $sng->getSearchFilters(); |
||
| 57 | } else { |
||
| 58 | // Scaffold search based on fields |
||
| 59 | $fields = Config::inst()->get($dataObject, 'db'); |
||
| 60 | if (isset($fields['Title'])) { |
||
| 61 | $filters['Title:PartialMatch'] = $FullQuery; |
||
| 62 | } |
||
| 63 | if (isset($fields['Name'])) { |
||
| 64 | $filters['Name:PartialMatch'] = $FullQuery; |
||
| 65 | } |
||
| 66 | if (isset($fields['Content'])) { |
||
| 67 | $filters['Content:PartialMatch'] = $FullQuery; |
||
| 68 | } |
||
| 69 | if (isset($fields['Description'])) { |
||
| 70 | $filters['Description:PartialMatch'] = $FullQuery; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $Results = $dataObject::get()->filterAny($filters); |
||
| 75 | if ($Results) { |
||
| 76 | foreach ($Results as $Result) { |
||
| 77 | if ($Result->canView()) { |
||
| 78 | $SearchList->push($Result); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $PaginatedList = new PaginatedList($SearchList, $request); |
||
| 86 | $data = array( |
||
| 87 | 'Results' => $PaginatedList, |
||
| 88 | 'Query' => DBField::create_field('Text', $Query), |
||
| 89 | 'Title' => _t('SimpleSearch.SearchResults', 'Search Results'), |
||
| 90 | 'YouSearchedFor' => _t('SimpleSearch.YouSearchFor', 'You searched for %s', [$Query]), |
||
| 91 | ); |
||
| 92 | return $this->customise($data)->renderWith(array('Page_results', 'Page')); |
||
| 93 | } |
||
| 120 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths