ImportDistributorsTask::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
/**
5
 * allows the creation of distributors from a CSV
6
 */
7
8
class ImportDistributorsTask extends ImportStockistsTask
9
{
10
    protected $title = "Import all the Distributors";
11
12
    protected $description = "Does not delete any record, it only updates and adds.";
13
14
    /**
15
     * excluding base folder
16
     *
17
     * e.g. assets/files/mycsv.csv
18
     * @var String
19
     */
20
    protected $fileLocation = "assets/Uploads/distributors.csv";
21
22
    /**
23
     *
24
     */
25
    public function run($request)
26
    {
27
        increase_time_limit_to(3600);
28
        set_time_limit(3600);
29
        increase_memory_limit_to('1024M');
30
        $this->readFile();
31
        $this->createDistributors();
32
    }
33
34
    /**
35
     *
36
     * here we actuall
37
     */
38
    protected function createDistributors()
39
    {
40
        flush();
41
        ob_end_flush();
42
        DB::alteration_message("================================================ CREATING distributors ================================================");
43
        ob_start();
44
        $distributorsCompleted = array();
0 ignored issues
show
Unused Code introduced by
$distributorsCompleted 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...
45
        $rowCount = 0;
46
        foreach ($this->csv as $row) {
47
            $rowCount++;
48
            //distributor page
49
            $name = trim($row["NAME"]);
50
            $distributor = Distributor::get()->filter(array("Name" => $name))->first();
51
            if (!$distributor) {
52
                $distributor = new Distributor();
53
                $distributor->Address1 = $row["ENTEREDADDRESS"];
0 ignored issues
show
Documentation introduced by
The property Address1 does not exist on object<Distributor>. 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...
54
                flush();
55
                ob_end_flush();
56
                DB::alteration_message(" --- Creating distributor: ".$row["NAME"], "created");
57
                ob_start();
58
            } else {
59
                flush();
60
                ob_end_flush();
61
                DB::alteration_message(" --- Updating distributor: ".$row["NAME"], "changed");
62
                ob_start();
63
            }
64
            $distributor->Name = $name;
65
            $distributor->IsDefault = false;
66
            $distributor->Email = $row["EMAIL"];
67
            $distributor->Phone = $row["PHONE"];
68
            $distributor->DisplayEmail = $row["EMAIL"];
69
            $distributor->WebAddress = $row["WEB"];
70
            $distributor->write();
71
        }
72
        flush();
73
        ob_end_flush();
74
        DB::alteration_message("====================== END ==========================");
75
        ob_start();
76
    }
77
}
78