| Conditions | 5 |
| Paths | 12 |
| Total Lines | 58 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 4 | Features | 4 |
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 |
||
| 41 | public function createQuery(array $params, $query) |
||
| 42 | { |
||
| 43 | $search = isset($params['search']) ? $params['search']:''; |
||
| 44 | |||
| 45 | if(!empty($search)){ |
||
| 46 | $q = \SolrUtils::escapeQueryChars($search); |
||
|
|
|||
| 47 | }else{ |
||
| 48 | $q = '*:*'; |
||
| 49 | } |
||
| 50 | |||
| 51 | $query->setQuery($q); |
||
| 52 | $query->addFilterQuery('entityName:job'); |
||
| 53 | $query->addFilterQuery('isActive:1'); |
||
| 54 | $query->addField('*'); |
||
| 55 | |||
| 56 | if(isset($params['location'])){ |
||
| 57 | /* @var Location $location */ |
||
| 58 | $location = $params['location']; |
||
| 59 | if(is_object($location->getCoordinates())){ |
||
| 60 | $coordinate = Util::convertLocationCoordinates($location); |
||
| 61 | |||
| 62 | $query->addFilterQuery( |
||
| 63 | sprintf( |
||
| 64 | '{!parent which="entityName:job" childQuery="entityName:location"}{!geofilt pt=%s sfield=point d=%d score="kilometers"}', |
||
| 65 | $coordinate, |
||
| 66 | $params['d'] |
||
| 67 | )); |
||
| 68 | $query->addParam( |
||
| 69 | 'locations.q', |
||
| 70 | sprintf( |
||
| 71 | 'entityName:location AND {!terms f=_root_ v=$row.id} AND {!geofilt pt=%s sfield=point d=%s}', |
||
| 72 | $coordinate, |
||
| 73 | $params['d'] |
||
| 74 | )); // join |
||
| 75 | |||
| 76 | $query->addField('locations:[subquery]') |
||
| 77 | ->addField('distance:min(geodist(points,'.$coordinate.'))'); |
||
| 78 | |||
| 79 | } |
||
| 80 | |||
| 81 | $query->addField('score'); |
||
| 82 | } |
||
| 83 | |||
| 84 | // boost newest jobs |
||
| 85 | $query->addParam('bf', 'recip(abs(ms(NOW/HOUR,datePublishStart)),3.16e-11,1,.1)'); |
||
| 86 | |||
| 87 | |||
| 88 | // adds facets into the result set. |
||
| 89 | $query->setFacet(true); |
||
| 90 | $query->addFacetField('regionList'); |
||
| 91 | $query->addFacetDateField('datePublishStart'); |
||
| 92 | |||
| 93 | // adds an additional 'highlights' section into the result set |
||
| 94 | $query->setHighlight(true); |
||
| 95 | $query->addHighlightField('title'); |
||
| 96 | |||
| 97 | return $query; |
||
| 98 | } |
||
| 99 | |||
| 112 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.