| Conditions | 10 |
| Paths | 54 |
| Total Lines | 33 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 137 | private function setDefaults() |
||
| 138 | { |
||
| 139 | if (empty($this->address)) { |
||
| 140 | $params = []; |
||
| 141 | if (!empty($this->disabledFields)) { |
||
| 142 | $requiredFields = array_diff(Address::$defaultRequiredFields, $this->disabledFields); |
||
| 143 | $params['requiredFields'] = $requiredFields; |
||
| 144 | } |
||
| 145 | $this->address = new Address($params); |
||
| 146 | } |
||
| 147 | |||
| 148 | if (count($this->allowedCountries) === 1) { |
||
| 149 | $this->country = country($this->allowedCountries[0]); |
||
| 150 | $this->address->country = $this->country->getIsoAlpha2(); |
||
| 151 | } |
||
| 152 | if(!empty($this->defaultCountry)) { |
||
| 153 | if(!in_array($this->defaultCountry, $this->allowedCountries) && !empty($this->allowedCountries)) { |
||
| 154 | throw new ErrorException("the set defaultCounty '{$this->defaultCountry}' must be one of the configured allowedCountries"); |
||
| 155 | } |
||
| 156 | $this->country = country($this->defaultCountry); |
||
| 157 | } |
||
| 158 | |||
| 159 | if (empty($this->submitText)) { |
||
| 160 | $this->submitText = Yii::t("addressform", "Send"); |
||
| 161 | } |
||
| 162 | $this->htmlOptions['id'] = $this->id; |
||
| 163 | if (!empty($this->htmlOptions)) { |
||
| 164 | foreach ($this->htmlOptions as $key => $value) { |
||
| 165 | $this->htmlOptions[$key] = $value; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | $this->defaultPlaceHolders(); |
||
| 170 | |||
| 193 |