| Conditions | 7 |
| Paths | 24 |
| Total Lines | 56 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 47 | public function createQuery(array $params, $query) |
||
| 48 | { |
||
| 49 | $search = isset($params['search']) ? $params['search']:''; |
||
| 50 | |||
| 51 | if(!empty($search)){ |
||
| 52 | $q = \SolrUtils::escapeQueryChars($search); |
||
|
|
|||
| 53 | }else{ |
||
| 54 | $q = '*:*'; |
||
| 55 | } |
||
| 56 | |||
| 57 | $query->setQuery($q); |
||
| 58 | $query->addFilterQuery('entityName:job'); |
||
| 59 | $query->addField('*'); |
||
| 60 | |||
| 61 | if(isset($params['sort'])){ |
||
| 62 | $sorts = $this->filterSort($params['sort']); |
||
| 63 | foreach($sorts as $field=>$order){ |
||
| 64 | $query->addSortField($field,$order); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if(isset($params['location'])){ |
||
| 69 | /* @var Location $location */ |
||
| 70 | $location = $params['location']; |
||
| 71 | if(is_object($location->getCoordinates())){ |
||
| 72 | $coordinate = Util::convertLocationCoordinates($location); |
||
| 73 | |||
| 74 | $query->addFilterQuery( |
||
| 75 | sprintf( |
||
| 76 | '{!parent which="entityName:job" childQuery="entityName:location"}{!geofilt pt=%s sfield=point d=%d score="kilometers"}', |
||
| 77 | $coordinate, |
||
| 78 | $params['d'] |
||
| 79 | )); |
||
| 80 | $query->addParam( |
||
| 81 | 'locations.q', |
||
| 82 | sprintf( |
||
| 83 | 'entityName:location AND {!terms f=_root_ v=$row.id} AND {!geofilt pt=%s sfield=point d=%s}', |
||
| 84 | $coordinate, |
||
| 85 | $params['d'] |
||
| 86 | )); // join |
||
| 87 | |||
| 88 | $query->addField('locations:[subquery]') |
||
| 89 | ->addField('distance:min(geodist(points,'.$coordinate.'))'); |
||
| 90 | |||
| 91 | } |
||
| 92 | |||
| 93 | $query->addField('score'); |
||
| 94 | |||
| 95 | $query->setFacet(true); |
||
| 96 | $query->addFacetField('regionList'); |
||
| 97 | $query->addFacetDateField('datePublishStart'); |
||
| 98 | |||
| 99 | } |
||
| 100 | |||
| 101 | return $query; |
||
| 102 | } |
||
| 103 | |||
| 158 | } |
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.