PopulateShopTableShippingTask   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 8
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A beforePopulate() 0 5 1
1
<?php
2
3
/**
4
 * @package silvershop-shipping
5
 */
6
class PopulateTableShippingTask extends BuildTask
7
{
8
    protected $title = "Populate Table Shipping Methods";
9
10
    protected $description = 'If no table shipping methods exist, it creates multiple different setups of table shipping.';
11
12
    public function run($request = null)
13
    {
14
        if (!DataObject::get_one('TableShippingMethod')) {
15
            $factory = Injector::inst()->create('FixtureFactory');
16
            $fixture = new YamlFixture('silvershop-shipping/tests/fixtures/TableShippingMethod.yml');
17
            $fixture->writeInto($factory);
18
            DB::alteration_message('Created table shipping methods', 'created');
19
        } else {
20
            DB::alteration_message('Some table shipping methods already exist. None were created.');
21
        }
22
    }
23
}
24
25
/**
26
 * Makes PopulateTableShippingTask get run before PopulateShopTask is run
27
 *
28
 * @package silvershop-shipping
29
 */
30
class PopulateShopTableShippingTask extends Extension
31
{
32
    public function beforePopulate()
33
    {
34
        $task = new PopulateTableShippingTask();
35
        $task->run();
36
    }
37
}
38