run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
nc 3
nop 1
1
<?php
2
3
/**
4
 * create standard country and regions.
5
 *
6
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
7
 * @package: ecommerce
8
 * @sub-package: tasks
9
 * @inspiration: Silverstripe Ltd, Jeremy
10
 **/
11
class EcommerceTaskCountryAndRegion extends BuildTask
12
{
13
    protected $title = 'Create standard countries and regions';
14
15
    protected $description = 'Adds all countries to the EcommerceCountry list';
16
17
    public function run($request)
18
    {
19
        $count = 0;
20
        $array = EcommerceCountry::get_country_dropdown();
21
        $allowedArray = EcommerceConfig::get('EcommerceCountry', 'allowed_country_codes');
22
        foreach ($array as $code => $name) {
23
            $ecommerceCountry = DataObject::get_one(
24
                'EcommerceCountry',
25
                array('Code' => Convert::raw2sql($code)),
26
                $cacheDataObjectGetOne = false
27
            );
28
            if ($ecommerceCountry) {
29
                //do nothing
30
                ++$count;
31
            } else {
32
                DB::alteration_message("adding $code to Ecommerce Country", 'created');
33
                $ecommerceCountry = EcommerceCountry::create();
34
                $ecommerceCountry->Code = $code;
0 ignored issues
show
Documentation introduced by
The property Code does not exist on object<EcommerceCountry>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
35
            }
36
            if ($allowedArray && count($allowedArray)) {
37
                if (in_array($code, $allowedArray)) {
38
                    //do nothing
39
                    $ecommerceCountry->DoNotAllowSales = 0;
40
                } else {
41
                    $ecommerceCountry->DoNotAllowSales = 1;
42
                }
43
            }
44
            $ecommerceCountry->Name = $name;
45
            $ecommerceCountry->write();
46
        }
47
        DB::alteration_message("Created / Checked $count Ecommerce Countries", 'edited');
48
    }
49
}
50
51
/**
52
 * update EcommerceCountry.DoNotAllowSales to 1 so that you can not sell to any country.
53
 *
54
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
55
 * @package: ecommerce
56
 * @sub-package: tasks
57
 * @inspiration: Silverstripe Ltd, Jeremy
58
 **/
59
class EcommerceTaskCountryAndRegion_DisallowAllCountries extends BuildTask
60
{
61
    protected $title = 'Disallows sale to all countries';
62
63
    protected $description = 'We add this task to reset all countries from Allow Sales to Disallow Sales - as a good starting point when selling to just a few countries';
64
65
    public function run($request)
66
    {
67
        $count = 0;
0 ignored issues
show
Unused Code introduced by
$count 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...
68
        $array = EcommerceCountry::get_country_dropdown();
0 ignored issues
show
Unused Code introduced by
$array 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...
69
        $allowedArray = EcommerceCountry::get()
70
            ->filter(array('DoNotAllowSales' => 0));
71
        if ($allowedArray->count()) {
72
            foreach ($allowedArray as $obj) {
73
                $obj->DoNotAllowSales = 1;
74
                $obj->write();
75
                DB::alteration_message('Disallowing sales to '.$obj->Name);
76
            }
77
        } else {
78
            DB::alteration_message('Could not find any countries that are allowed', 'created');
79
        }
80
    }
81
}
82
/**
83
 * update EcommerceCountry.DoNotAllowSales to 0 so that you can sell to all countries.
84
 *
85
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
86
 * @package: ecommerce
87
 * @sub-package: tasks
88
 * @inspiration: Silverstripe Ltd, Jeremy
89
 **/
90
class EcommerceTaskCountryAndRegion_AllowAllCountries extends BuildTask
91
{
92
    protected $title = 'Allows sale to all countries';
93
94
    protected $description = 'We add this task to reset all countries from Allow Sales to Disallow Sales - as a good starting point when selling to just a few countries';
95
96
    public function run($request)
97
    {
98
        $count = 0;
0 ignored issues
show
Unused Code introduced by
$count 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...
99
        $array = EcommerceCountry::get_country_dropdown();
0 ignored issues
show
Unused Code introduced by
$array 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...
100
        $allowedArray = EcommerceCountry::get()
101
            ->filter(array('DoNotAllowSales' => 1));
102
        if ($allowedArray->count()) {
103
            foreach ($allowedArray as $obj) {
104
                $obj->DoNotAllowSales = 0;
105
                $obj->write();
106
                DB::alteration_message('Disallowing sales to '.$obj->Name);
107
            }
108
        } else {
109
            DB::alteration_message('Could not find any countries that are not allowed', 'created');
110
        }
111
    }
112
}
113