updateEcommerceDevMenuRegularMaintenance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
class EcommerceProductVariationTaskDeleteAll extends BuildTask
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...
4
{
5
    protected $title = "Deletes all the variations and associated data";
6
7
    protected $description = "Deletes ALL variations and all associated data, careful.";
8
9
    protected $tableArray = array(
10
        "ProductVariation",
11
        "ProductVariation_AttributeValues",
12
        "Product_VariationAttributes",
13
        "ProductAttributeType",
14
        "ProductAttributeValue"
15
    );
16
17
    public function run($request)
0 ignored issues
show
Coding Style introduced by
run uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18
    {
19
        $productVariationArrayID = array();
0 ignored issues
show
Unused Code introduced by
$productVariationArrayID 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...
20 View Code Duplication
        if (empty($_GET["live"])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
            $live = false;
22
        } else {
23
            $live = intval($_GET["live"]) == 1 ? true : false;
24
        }
25
        if ($live) {
26
            DB::alteration_message("this is a live task", "deleted");
27
        } else {
28
            DB::alteration_message("this is a test only. If you add a live=1 get variable then you can make it for real ;-)", "created");
29
        }
30
        foreach ($this->tableArray as $table) {
31
            $sql = "DELETE FROM \"$table\"";
32
            DB::alteration_message("<pre>DELETING FROM $table: <br /><br />".$sql."</pre>");
33
            if ($live) {
34
                DB::query($sql);
35
            }
36
            $sql = "SELECT COUNT(ID) FROM \"$table\"";
37
            $count = DB::query($sql)->value();
38
            if ($count == 0) {
39
                $style = "created";
40
            } else {
41
                $style = "deleted";
42
            }
43
            DB::alteration_message(" **** COMPLETED, NUMBER OF REMAINING RECORD: ".$count." **** ", $style);
44
        }
45
    }
46
}
47
48
class EcommerceProductVariationTaskDeleteAll_EXT extends Extension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
49
{
50
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions 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...
51
        "ecommerceproductvariationtaskdeletevariations" => true
52
    );
53
54
    //NOTE THAT updateEcommerceDevMenuConfig adds to Config options
55
    //but you can als have: updateEcommerceDevMenuDebugActions
56
    public function updateEcommerceDevMenuRegularMaintenance($buildTasks)
57
    {
58
        $buildTasks[] = "ecommerceproductvariationtaskdeleteall";
59
        return $buildTasks;
60
    }
61
62
    public function ecommerceproductvariationtaskdeleteall($request)
63
    {
64
        $this->owner->runTask("ecommerceproductvariationtaskdeleteall", $request);
65
    }
66
}
67