Conditions | 13 |
Paths | 90 |
Total Lines | 47 |
Code Lines | 34 |
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 |
||
63 | public function loadTranslatedValues($countryID = 0, $variableOrMethod = '') |
||
64 | { |
||
65 | $translation = null; |
||
66 | if (! $countryID) { |
||
67 | $countryObject = CountryPrice_EcommerceCountry::get_real_country(); |
||
68 | if ($countryObject) { |
||
69 | $countryID = $countryObject->ID; |
||
70 | } |
||
71 | } |
||
72 | if ($countryID) { |
||
73 | $key = $this->owner->ID.'_'.$countryID; |
||
74 | if (isset(self::$_translations[$key])) { |
||
75 | $translation = self::$_translations[$key]; |
||
76 | } else { |
||
77 | $translation = $this->owner->getRealEcommerceTranslation($countryID); |
||
78 | self::$_translations[$key] = $translation; |
||
79 | } |
||
80 | } |
||
81 | if ($translation) { |
||
82 | $fieldsToReplace = $translation->FieldsToReplace(); |
||
83 | foreach ($fieldsToReplace as $replaceFields) { |
||
84 | $pageField = $replaceFields->PageField; |
||
85 | $pageFieldTranslated = $pageField . 'Translated'; |
||
86 | $translationField = $replaceFields->TranslationField; |
||
87 | if (! $variableOrMethod || $variableOrMethod === $pageField) { |
||
88 | if ($translation->hasMethod($translationField)) { |
||
89 | $this->owner->$pageField = $translation->$translationField(); |
||
90 | $this->owner->$pageFieldTranslated = $translation->$translationField(); |
||
91 | } else { |
||
92 | $this->owner->$pageField = $translation->$translationField; |
||
93 | $this->owner->$pageFieldTranslated = $translation->$translationField; |
||
94 | } |
||
95 | } |
||
96 | if ($variableOrMethod) { |
||
97 | return $this->owner->$pageField; |
||
98 | } |
||
99 | } |
||
100 | } else { |
||
101 | if ($variableOrMethod) { |
||
102 | if ($translation->hasMethod($variableOrMethod)) { |
||
103 | return $this->owner->$variableOrMethod(); |
||
104 | } else { |
||
105 | return $this->owner->$variableOrMethod; |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
176 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.