getCountryDescription()   D
last analyzed

Complexity

Conditions 9
Paths 7

Size

Total Lines 36
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 4.909
c 0
b 0
f 0
cc 9
eloc 20
nc 7
nop 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
class DiscountCouponOptionCountriesExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        "CountryDescription" => "Varchar"
13
    );
14
15
    private static $summary_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        "CountryDescription" => "CountryDescription"
17
    );
18
19
20
    private static $field_labels = array(
0 ignored issues
show
Unused Code introduced by
The property $field_labels is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
        "CountryDescription" => "Where"
22
    );
23
24
25
    private static $many_many = array(
0 ignored issues
show
Unused Code introduced by
The property $many_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
        "IncludedCountries" => "EcommerceCountry",
27
        "ExcludedCountries" => "EcommerceCountry"
28
    );
29
30
//    private static $belongs_many_many = array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
//
32
//    );
33
34
35
36
    public function getCountryDescription()
37
    {
38
        $returnString = '';
0 ignored issues
show
Unused Code introduced by
$returnString is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
        $includedCountries = $this->owner->IncludedCountries();
40
        $excludedCountries = $this->owner->ExcludedCountries();
41
        //first situation: no country information => ALLOW => return NULL to ignore this.
42
        if ($includedCountries->count() == 0 && $excludedCountries->count() == 0) {
43
            return _t('DiscountCouponOptionCountriesExtension.AVAILABLE_IN_ALL_COUNTRIES', 'Available in all countries');
44
        }
45
46
        //second situation: includes and excludes
47
        if ($includedCountries->count() > 0 && $excludedCountries->count() > 0) {
48
            $includeArray = $includedCountries->column('Code');
49
            $excludeArray = $excludedCountries->column('Code');
50
            foreach ($includeArray as $key => $countryCode) {
51
                if (in_array($countryCode, $excludeArray)) {
52
                    unset($includeArray[$key]);
53
                }
54
            }
55
            return  _t('DiscountCouponOptionCountriesExtension.AVAILABLE_IN', 'Available in: ').implode(', ', $includeArray).
56
                    _t('DiscountCouponOptionCountriesExtension.SPECIFICALLY_EXCLUDED', ' || Specifically excluded: ').implode(', ', $excludeArray);
57
            //...
58
        }
59
60
        //third situation: is it included?
61
        if ($includedCountries->count() > 0) {
62
            $includeArray = $includedCountries->column('Code');
63
            return _t('DiscountCouponOptionCountriesExtension.AVAILABLE_IN', 'Available in: ').implode(', ', $includeArray);
64
        }
65
66
        //fourth situation: is it excluded?
67
        if ($excludedCountries->count() > 0) {
68
            $excludeArray = $excludedCountries->column('Code');
69
            return _t('DiscountCouponOptionCountriesExtension.NOT_AVAILABLE_IN', 'Not available in: ').implode(', ', $excludeArray);
70
        }
71
    }
72
}
73