| Conditions | 7 |
| Paths | 20 |
| Total Lines | 51 |
| 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 |
||
| 107 | private function getSearchParameters(array $keywords, $languageId, $locationId, $included, $excluded) |
||
| 108 | { |
||
| 109 | $searchParameters = []; |
||
| 110 | |||
| 111 | //Create Language Parameter |
||
| 112 | if (! is_null($languageId)) { |
||
| 113 | $languageParameter = new LanguageSearchParameter(); |
||
| 114 | $language = new Language(); |
||
| 115 | $language->setId($languageId); |
||
| 116 | $languageParameter->setLanguages([$language]); |
||
| 117 | $searchParameters[] = $languageParameter; |
||
| 118 | } |
||
| 119 | |||
| 120 | //Create Location Parameter |
||
| 121 | if (! is_null($locationId)) { |
||
| 122 | $locationParameter = new LocationSearchParameter(); |
||
| 123 | $location = new Location(); |
||
| 124 | $location->setId($locationId); |
||
| 125 | $locationParameter->setLocations([$location]); |
||
| 126 | $searchParameters[] = $locationParameter; |
||
| 127 | } |
||
| 128 | |||
| 129 | //Network Settings |
||
| 130 | $networkSetting = new NetworkSetting(); |
||
| 131 | $networkSetting->setTargetGoogleSearch(true); |
||
| 132 | $networkSetting->setTargetSearchNetwork(false); |
||
| 133 | $networkSetting->setTargetContentNetwork(false); |
||
| 134 | $networkSetting->setTargetPartnerSearchNetwork(false); |
||
| 135 | |||
| 136 | $networkSearchParameter = new NetworkSearchParameter(); |
||
| 137 | $networkSearchParameter->setNetworkSetting($networkSetting); |
||
| 138 | $searchParameters[] = $networkSearchParameter; |
||
| 139 | |||
| 140 | // Create related to query search parameter. |
||
| 141 | $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); |
||
| 142 | $relatedToQuerySearchParameter->setQueries($keywords); |
||
| 143 | $searchParameters[] = $relatedToQuerySearchParameter; |
||
| 144 | |||
| 145 | if (! is_null($included) || ! is_null($excluded)) { |
||
| 146 | $ideaTextFilterSearchParameter = new IdeaTextFilterSearchParameter(); |
||
| 147 | if (! is_null($included)) { |
||
| 148 | $ideaTextFilterSearchParameter->setIncluded($included); |
||
| 149 | } |
||
| 150 | if (! is_null($excluded)) { |
||
| 151 | $ideaTextFilterSearchParameter->setExcluded($excluded); |
||
| 152 | } |
||
| 153 | $searchParameters[] = $ideaTextFilterSearchParameter; |
||
| 154 | } |
||
| 155 | |||
| 156 | return $searchParameters; |
||
| 157 | } |
||
| 158 | } |
||
| 159 |