| Conditions | 8 |
| Paths | 9 |
| Total Lines | 36 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 72 |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 23 | public function run($request) { |
||
| 24 | $message = ElasticaUtil::getPrinter(); |
||
| 25 | |||
| 26 | $locales = array(); |
||
| 27 | |||
| 28 | if ($this->locale == null) { |
||
| 29 | if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
||
| 30 | $this->locale = \Translatable::get_current_locale(); |
||
|
|
|||
| 31 | } else { |
||
| 32 | foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) { |
||
| 33 | array_push($locales, $code); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | // search SiteTree showing highlights |
||
| 39 | $query = $request->getVar('q'); |
||
| 40 | $es = new \ElasticSearcher(); |
||
| 41 | $es->setStart(0); |
||
| 42 | $es->setPageLength(20); |
||
| 43 | $es->addFilter('IsInSiteTree', true); |
||
| 44 | $results = $es->search($query); |
||
| 45 | foreach ($results as $result) { |
||
| 46 | $title = '['.$result->ClassName.', '.$result->ID.'] '; |
||
| 47 | $title .= $result->Title; |
||
| 48 | $message($title); |
||
| 49 | if ($result->SearchHighlightsByField->Content) { |
||
| 50 | foreach ($result->SearchHighlightsByField->Content as $highlight) { |
||
| 51 | $message("- ".$highlight->Snippet); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | echo "\n\n"; |
||
| 56 | } |
||
| 57 | |||
| 58 | } |
||
| 59 | |||
| 61 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: