| Conditions | 11 |
| Paths | 31 |
| Total Lines | 49 |
| Code Lines | 33 |
| Lines | 18 |
| Ratio | 36.73 % |
| 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 |
||
| 183 | public function requireDefaultRecords() |
||
| 184 | { |
||
| 185 | parent::requireDefaultRecords(); |
||
| 186 | if(Config::inst()->get('CountryPrice_Translation', 'automatically_create_dummy_translations_for_products_and_productgroups')) { |
||
| 187 | $prices = CountryPrice::get(); |
||
| 188 | $ecommerceCountries = array(); |
||
| 189 | foreach($prices as $price) { |
||
| 190 | if($countryObject = $price->CountryObject()) { |
||
| 191 | if($buyable = $price->Buyable()) { |
||
| 192 | if($buyable instanceof Product) { |
||
| 193 | $filter = array( |
||
| 194 | 'EcommerceCountryID' => $countryObject->ID, |
||
| 195 | 'ParentID' => $buyable->ID |
||
| 196 | ); |
||
| 197 | $ecommerceCountries[$countryObject->ID] = $countryObject; |
||
| 198 | View Code Duplication | if(! CountryPrice_Translation::get()->filter($filter)->first()) { |
|
| 199 | DB::alteration_message( |
||
| 200 | 'Creating fake translation for '.$buyable->Title.' for country '.$countryObject->Code, |
||
| 201 | 'created' |
||
| 202 | ); |
||
| 203 | $obj = CountryPrice_Translation::create($filter); |
||
| 204 | $obj->WithoutTranslation = true; |
||
| 205 | $obj->write(); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | if(count($ecommerceCountries)) { |
||
| 212 | foreach(ProductGroup::get() as $productGroup) { |
||
| 213 | foreach($ecommerceCountries as $countryID => $countryObject) { |
||
| 214 | $filter = array( |
||
| 215 | 'EcommerceCountryID' => $countryObject->ID, |
||
| 216 | 'ParentID' => $productGroup->ID |
||
| 217 | ); |
||
| 218 | View Code Duplication | if(! CountryPrice_Translation::get()->filter($filter)->first()) { |
|
| 219 | DB::alteration_message( |
||
| 220 | 'Creating fake translation for '.$productGroup->Title.' for country '.$countryObject->Code, |
||
| 221 | 'created' |
||
| 222 | ); |
||
| 223 | $obj = CountryPrice_Translation::create($filter); |
||
| 224 | $obj->WithoutTranslation = true; |
||
| 225 | $obj->write(); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | } |
||
| 229 | } |
||
| 230 | } |
||
| 231 | } |
||
| 232 | |||
| 234 |
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.