Completed
Push — master ( c612e9...50e7fd )
by
unknown
10s
created

BantenprovNilaiSeeder::insertData()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 39
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 29
nc 3
nop 0
dl 0
loc 39
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Database\Seeder;
4
5
/**
6
 * Usage : 
7
 * [1] $ composer dump-autoload -o
8
 * [2] $ php artisan db:seed --class=UserSeeder
9
 */
10
11
class BantenprovNilaiSeeder 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...
12
{
13
    /* text color */
14
    protected $RED     ="\033[0;31m";
15
    protected $CYAN    ="\033[0;36m";
16
    protected $YELLOW  ="\033[1;33m";
17
    protected $ORANGE  ="\033[0;33m"; 
18
    protected $PUR     ="\033[0;35m";
19
    protected $GRN     ="\e[32m";
20
    protected $WHI     ="\e[37m";
21
    protected $NC      ="\033[0m";
22
23
    /* File name */
24
    /* location : /databse/seeds/file_name.csv */
25
    protected $fileName = "BantenprovNilaiSeeder.csv";
26
27
    /* 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...
28
    protected $textInfo = true;
29
30
    /* model class */
31
    protected $model;
32
33
    /* __construct */
34
    public function __construct(){
35
36
        $this->model = new Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
37
38
    }
39
40
    /**
41
     * Run the database seeds.
42
     *
43
     * @return void
44
     */
45
    public function run()
46
    {        
47
        $this->insertData();
48
    }
49
50
    /* function insert data */
51
    protected function insertData()
52
    {
53
        /* silahkan di rubah sesuai kebutuhan */
54
        foreach($this->readCSV() as $data){          
55
56
            $this->model->create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
57
                'user_id' => $data['user_id'],
58
                'nomor_un' => $data['nomor_un'],
59
                'siswa_id' => $data['siswa_id'],
60
                'akademik_id' => $data['akademik_id'],
61
                'prestasi_id' => $data['prestasi_id'],
62
                'zona_id' => $data['zona_id'],
63
                'sktm_id' => $data['sktm_id'],
64
            ]);
65
            
66
            if($this->textInfo){                
67
                echo "============[DATA]============\n";
68
                $this->orangeText('user_id : ').$this->greenText($data['user_id']);
69
                echo"\n";
70
                $this->orangeText('nomor_un : ').$this->greenText($data['nomor_un']);
71
                echo"\n";
72
                $this->orangeText('siswa_id : ').$this->greenText($data['siswa_id']);
73
                echo"\n";
74
                $this->orangeText('akademik_id : ').$this->greenText($data['akademik_id']);
75
                echo"\n";
76
                $this->orangeText('prestasi_id : ').$this->greenText($data['prestasi_id']);
77
                echo"\n";
78
                $this->orangeText('zona_id : ').$this->greenText($data['zona_id']);
79
                echo"\n";
80
                $this->orangeText('sktm_id : ').$this->greenText($data['sktm_id']);
81
                echo"\n";
82
                echo "============[DATA]============\n\n";
83
            }
84
            
85
        }
86
87
        $this->greenText('[ SEEDER DONE ]');
88
        echo"\n\n";
89
    }
90
91
    /* text color: orange */
92
    protected function orangeText($text)
93
    {    
94
        printf($this->ORANGE.$text.$this->NC);
95
    }
96
97
    /* text color: green */
98
    protected function greenText($text)
99
    {    
100
        printf($this->GRN.$text.$this->NC);
101
    }
102
103
    /* function read CSV file */
104
    protected function readCSV()
105
    {
106
        /* Silahkan di rubah sesuai struktur file csv */
107
        $file = fopen(database_path("seeds/".$this->fileName), "r");
108
        $all_data = array();
109
        $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...
110
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){            
111
            $all_data[] = ['user_id' => $data[0], 
112
                           'nomor_un' => $data[1],
113
                           'siswa_id' => $data[2],
114
                           'akademik_id' => $data[3],
115
                           'prestasi_id' => $data[4],
116
                           'zona_id' => $data[5],
117
                           'sktm_id' => $data[6],
118
                        ];
119
        }        
120
        fclose($file);
121
122
        return  $all_data;
123
    }
124
}
125