| Conditions | 9 |
| Paths | 48 |
| Total Lines | 53 |
| 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 |
||
| 62 | public function __construct(InfoEncodeDecodeCityOptions $params) |
||
| 63 | { |
||
| 64 | if (!empty($params->locationCode)) { |
||
| 65 | $this->locationInformation = new LocationInformation( |
||
| 66 | LocationInformation::TYPE_LOCATION, |
||
| 67 | strtoupper($params->locationCode), |
||
| 68 | null |
||
| 69 | ); |
||
| 70 | } elseif (!empty($params->locationName)) { |
||
| 71 | //Only allow lowercase input for phonetic searches |
||
| 72 | if ($params->searchMode !== InfoEncodeDecodeCityOptions::SEARCHMODE_PHONETIC) { |
||
| 73 | $params->locationName = strtoupper($params->locationName); |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->locationInformation = new LocationInformation( |
||
| 77 | LocationInformation::TYPE_ALL, |
||
| 78 | null, |
||
| 79 | $params->locationName |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!empty($params->searchMode)) { |
||
| 84 | $this->requestOption = new RequestOption( |
||
| 85 | $params->searchMode, |
||
| 86 | SelectionDetails::OPT_SEARCH_ALGORITHM |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | |||
| 90 | if (!empty($params->selectResult)) { |
||
| 91 | $selDet = new SelectionDetails( |
||
| 92 | $params->selectResult, |
||
| 93 | SelectionDetails::OPT_LOCATION_TYPE |
||
| 94 | ); |
||
| 95 | |||
| 96 | if (!($this->requestOption instanceof RequestOption)) { |
||
| 97 | $this->requestOption = new RequestOption(); |
||
| 98 | $this->requestOption->selectionDetails = $selDet; |
||
| 99 | } else { |
||
| 100 | $this->requestOption->otherSelectionDetails[] = $selDet; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | if (!is_null($params->restrictCountry) || !is_null($params->restrictState)) { |
||
| 105 | $params->restrictState = $this->upperOrNull($params->restrictState); |
||
| 106 | |||
| 107 | $params->restrictCountry = $this->upperOrNull($params->restrictCountry); |
||
| 108 | |||
| 109 | $this->countryStateRestriction = new CountryStateRestriction( |
||
| 110 | $params->restrictCountry, |
||
| 111 | $params->restrictState |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 127 |