Completed
Push — master ( 59c799...149ad0 )
by Will
02:15
created

code/tasks/FixElementTitle.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
class FixElementTitle extends BuildTask
3
{
4
5
    protected $title = 'Fix Element title';
6
7
    protected $description = 'Now that element label has been removed and widget title been created, we need to move the values from the label field to the title field';
8
9
    public function run($request)
10
    {
11
        $elements = BaseElement::get();
12 View Code Duplication
        foreach ($elements as $element) {
13
            $label = DB::query('SELECT Label FROM "BaseElement" WHERE "ID" = ' . $element->ID)->record();
14
            $element->Title = $label['Label'];
15
16
            $label = DB::query('UPDATE "Widget" SET "Title" = \'' . Convert::raw2sql($label['Label']) . '\' WHERE "ID" = ' . $element->ID)->record();
0 ignored issues
show
$label 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...
17
        }
18
19
        $origStage = Versioned::current_stage();
20
        Versioned::reading_stage('Live');
21
22
        $elements = BaseElement::get();
23 View Code Duplication
        foreach ($elements as $element) {
24
            $label = DB::query('SELECT Label FROM "BaseElement_Live" WHERE "ID" = ' . $element->ID)->record();
25
26
            $label = DB::query('UPDATE "Widget_Live" SET "Title" = \'' . Convert::raw2sql($label['Label']) . '\' WHERE "ID" = ' . $element->ID)->record();
0 ignored issues
show
$label 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...
27
        }
28
29
        Versioned::reading_stage($origStage);
30
    }
31
}
32