CountryPrice_OrderFormAddressExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateFields() 0 21 4
1
<?php
2
3
4
class CountryPrice_OrderFormAddressExtension extends Extension
5
{
6
    public function updateFields($fields)
7
    {
8
        $shippingField = $fields->dataFieldByName('ShippingCountry');
9
        $originalSource = $shippingField->getSource();
10
        $newSource = $originalSource;
11
        $allowedCountries = CountryPrice_EcommerceCountry::get_sibling_countries();
12
        $allowedCountries = $allowedCountries->exclude('OnlyShowChildrenInDropdowns', true);
13
        if ($allowedCountries->count()) {
14
            $allowedCountryCodes = $allowedCountries->column('Code');
15
            foreach ($newSource as $key => $value) {
16
                if (! in_array($key, $allowedCountryCodes)) {
17
                    unset($newSource[$key]);
18
                }
19
            }
20
            $shippingField->setSource($newSource);
21
            $js = '
22
                var CountryPrice_SetCountriesForDelivery_Original = '.Convert::array2json($originalSource).';
23
                var CountryPrice_SetCountriesForDelivery_New      = '.Convert::array2json($newSource).';';
24
            Requirements::customScript($js, 'CountryPrice_OrderFormAddressExtension_updateFields');
25
        }
26
    }
27
}
28