| Conditions | 7 |
| Paths | 20 |
| Total Lines | 51 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 121 | private function getSearchParameters(array $keywords, $languageId, $locationId, $included, $excluded) |
||
| 122 | { |
||
| 123 | $searchParameters = []; |
||
| 124 | |||
| 125 | //Create Language Parameter |
||
| 126 | if (!is_null($languageId)) { |
||
| 127 | $languageParameter = new LanguageSearchParameter(); |
||
| 128 | $language = new Language(); |
||
| 129 | $language->setId($languageId); |
||
| 130 | $languageParameter->setLanguages([$language]); |
||
| 131 | $searchParameters[] = $languageParameter; |
||
| 132 | } |
||
| 133 | |||
| 134 | //Create Location Parameter |
||
| 135 | if (!is_null($locationId)) { |
||
| 136 | $locationParameter = new LocationSearchParameter(); |
||
| 137 | $location = new Location(); |
||
| 138 | $location->setId($locationId); |
||
| 139 | $locationParameter->setLocations([$location]); |
||
| 140 | $searchParameters[] = $locationParameter; |
||
| 141 | } |
||
| 142 | |||
| 143 | //Network Settings |
||
| 144 | $networkSetting = new NetworkSetting(); |
||
| 145 | $networkSetting->setTargetGoogleSearch(true); |
||
| 146 | $networkSetting->setTargetSearchNetwork(false); |
||
| 147 | $networkSetting->setTargetContentNetwork(false); |
||
| 148 | $networkSetting->setTargetPartnerSearchNetwork(false); |
||
| 149 | |||
| 150 | $networkSearchParameter = new NetworkSearchParameter(); |
||
| 151 | $networkSearchParameter->setNetworkSetting($networkSetting); |
||
| 152 | $searchParameters[] = $networkSearchParameter; |
||
| 153 | |||
| 154 | // Create related to query search parameter. |
||
| 155 | $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); |
||
| 156 | $relatedToQuerySearchParameter->setQueries($keywords); |
||
| 157 | $searchParameters[] = $relatedToQuerySearchParameter; |
||
| 158 | |||
| 159 | if(!is_null($included) or !is_null($excluded)){ |
||
| 160 | $ideaTextFilterSearchParameter = new IdeaTextFilterSearchParameter(); |
||
| 161 | if(!is_null($included)) { |
||
| 162 | $ideaTextFilterSearchParameter->setIncluded($included); |
||
| 163 | } |
||
| 164 | if(!is_null($excluded)) { |
||
| 165 | $ideaTextFilterSearchParameter->setExcluded($excluded); |
||
| 166 | } |
||
| 167 | $searchParameters[] = $ideaTextFilterSearchParameter; |
||
| 168 | } |
||
| 169 | |||
| 170 | return $searchParameters; |
||
| 171 | } |
||
| 172 | } |
||
| 173 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: