Completed
Push — master ( 4eaaa2...06a8e1 )
by
unknown
10s
created

BantenprovPrestasiSeederPrestasi::greenText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
use Illuminate\Database\Seeder;
3
/**
4
 * Usage :
5
 * [1] $ composer dump-autoload -o
6
 * [2] $ php artisan db:seed --class=BantenprovPrestasiSeederPrestasi
7
 */
8
class BantenprovPrestasiSeederPrestasi 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 = "BantenprovPrestasiSeederPrestasi.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\Prestasi\Models\Bantenprov\Prestasi\Prestasi;
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 View Code Duplication
        foreach($this->readCSV() as $data){
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...
44
45
46
        	$this->model->create([
47
				'nomor_un' => $data['nomor_un'],
48
				'master_prestasi_id' => $data['master_prestasi_id'],
49
				'nama_lomba' => $data['nama_lomba'],
50
				'nilai' => $data['nilai'],
51
            	'user_id' => $data['user_id'],
52
53
        	]);
54
55
56
        }
57
58
        if($this->textInfo){
59
            echo "============[DATA]============\n";
60
			$this->orangeText('nomor_un : ').$this->greenText($data['nomor_un']);
0 ignored issues
show
Bug introduced by
The variable $data seems to be defined by a foreach iteration on line 43. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
61
			echo"\n";
62
			$this->orangeText('master_prestasi_id : ').$this->greenText($data['master_prestasi_id']);
63
			echo"\n";
64
			$this->orangeText('nama_lomba : ').$this->greenText($data['nama_lomba']);
65
			echo"\n";
66
			$this->orangeText('nilai : ').$this->greenText($data['nilai']);
67
			echo"\n";
68
            $this->orangeText('user_id : ').$this->greenText($data['user_id']);
69
			echo"\n";
70
71
            echo "============[DATA]============\n\n";
72
        }
73
74
        $this->greenText('[ SEEDER DONE ]');
75
        echo"\n\n";
76
    }
77
    /* text color: orange */
78
    protected function orangeText($text)
79
    {
80
        printf($this->ORANGE.$text.$this->NC);
81
    }
82
    /* text color: green */
83
    protected function greenText($text)
84
    {
85
        printf($this->GRN.$text.$this->NC);
86
    }
87
    /* function read CSV file */
88 View Code Duplication
    protected function readCSV()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
89
    {
90
        $file = fopen(database_path("seeds/".$this->fileName), "r");
91
        $all_data = array();
92
        $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...
93
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){
94
            $all_data[] = [
95
                'nomor_un' => $data[0],
96
                'master_prestasi_id' => $data[1],
97
                'nama_lomba' => $data[2],
98
                'nilai' => $data[3],
99
                'user_id' => $data[4],
100
            ];
101
        }
102
        fclose($file);
103
        return  $all_data;
104
    }
105
}
106