BantenprovProgramKeahlianSeederProgramKeahlian   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 101
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 4 1
B insertData() 0 41 3
A orangeText() 0 4 1
A greenText() 0 4 1
A readCSV() 0 16 2
1
<?php
2
use Illuminate\Database\Seeder;
3
/**
4
 * Usage :
5
 * [1] $ composer dump-autoload -o
6
 * [2] $ php artisan db:seed --class=BantenprovProgramKeahlianSeederProgramKeahlian
7
 */
8
class BantenprovProgramKeahlianSeederProgramKeahlian extends Seeder
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...
9
{
10
    /* text color */
11
    protected $RED     ="\033[0;31m";
12
    protected $CYAN    ="\033[0;36m";
13
    protected $YELLOW  ="\033[1;33m";
14
    protected $ORANGE  ="\033[0;33m";
15
    protected $PUR     ="\033[0;35m";
16
    protected $GRN     ="\e[32m";
17
    protected $WHI     ="\e[37m";
18
    protected $NC      ="\033[0m";
19
    /* File name */
20
    /* location : /databse/seeds/file_name.csv */
21
    protected $fileName = "BantenprovProgramKeahlianSeederProgramKeahlian.csv";
22
    /* text info : default (true) */
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
    protected $textInfo = true;
24
    /* model class */
25
    protected $model;
26
    /* __construct */
27
    public function __construct(){
28
        $this->model = new Bantenprov\ProgramKeahlian\Models\Bantenprov\ProgramKeahlian\ProgramKeahlian;
29
    }
30
    /**
31
     * Run the database seeds.
32
     *
33
     * @return void
34
     */
35
    public function run()
36
    {
37
        $this->insertData();
38
    }
39
    /* function insert data */
40
    protected function insertData()
41
    {
42
        /* silahkan di rubah sesuai kebutuhan */
43
        $row = 1;
44
        $total = count($this->readCSV());
45
46
        $this->greenText("\n[ SEEDER START ]\n");
47
48
        foreach($this->readCSV() as $data){
49
50
            $this->model->withTrashed()->updateOrCreate(
51
                [
52
                    'id'    => $data['id'],
53
                ],
54
                [
55
                    'id'            => $data['id'],
56
                    'label'         => $data['label'],
57
                    'keterangan'    => $data['keterangan'],
58
                    'user_id'       => $data['user_id'],
59
                ]
60
            );
61
62
            if($this->textInfo){
63
                echo"\n";
64
                echo "============[DATA {$row}/{$total}]============\n";
65
                $this->orangeText('id : ').$this->greenText($data['id']);
66
                echo"\n";
67
                $this->orangeText('label : ').$this->greenText($data['label']);
68
                echo"\n";
69
                $this->orangeText('keterangan : ').$this->greenText($data['keterangan']);
70
                echo"\n";
71
                $this->orangeText('user_id : ').$this->greenText($data['user_id']);
72
                echo"\n";
73
                echo "============[DATA {$row}/{$total}]============\n";
74
            }
75
76
            $row++;
77
        }
78
79
        $this->greenText("\n[ SEEDER DONE ]\n");
80
    }
81
    /* text color: orange */
82
    protected function orangeText($text)
83
    {
84
        printf($this->ORANGE.$text.$this->NC);
85
    }
86
    /* text color: green */
87
    protected function greenText($text)
88
    {
89
        printf($this->GRN.$text.$this->NC);
90
    }
91
    /* function read CSV file */
92
    protected function readCSV()
93
    {
94
        $file = fopen(database_path("seeds/".$this->fileName), "r");
95
        $all_data = array();
96
        $row = 1;
0 ignored issues
show
Unused Code introduced by
$row 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...
97
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){
98
            $all_data[] = [
99
                'id'            => $data[0],
100
                'label'         => $data[1],
101
                'keterangan'    => $data[2],
102
                'user_id'       => $data[3],
103
            ];
104
        }
105
        fclose($file);
106
        return  $all_data;
107
    }
108
}
109