BantenprovAnggaranSeeder   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 108
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
B insertData() 0 35 3
A __construct() 0 3 1
A run() 0 3 1
A readCSV() 0 18 2
A greenText() 0 3 1
A orangeText() 0 3 1
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 BantenprovAnggaranSeeder extends Seeder
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 = "BantenprovAnggaranSeederAnggaran.csv";
26
27
    /* text info : default (true) */
28
    protected $textInfo = true;
29
30
    /* model class */
31
    protected $model;
32
33
    /* __construct */
34
    public function __construct(){
35
36
        $this->model = new Bantenprov\Anggaran\Models\Bantenprov\Anggaran\Anggaran;
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([
57
                'user_id' 				=> $data['user_id'],
58
                'label' 				=> $data['label'],
59
                'description' 			=> $data['description'],
60
                'group_egovernment_id' 	=> $data['group_egovernment_id'],
61
                'sector_egovernment_id' => $data['sector_egovernment_id'],
62
                'link'                  => $data['link'],
63
            ]);
64
65
            if($this->textInfo){                
66
                echo "============[DATA]============\n";
67
                $this->orangeText('user_id : ').$this->greenText($data['user_id']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->orangeText('user_id : ') targeting BantenprovAnggaranSeeder::orangeText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->greenText($data['user_id']) targeting BantenprovAnggaranSeeder::greenText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
                echo"\n";
69
                $this->orangeText('label : ').$this->greenText($data['label']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->greenText($data['label']) targeting BantenprovAnggaranSeeder::greenText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->orangeText('label : ') targeting BantenprovAnggaranSeeder::orangeText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
                echo"\n";
71
                $this->orangeText('description : ').$this->greenText($data['description']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->orangeText('description : ') targeting BantenprovAnggaranSeeder::orangeText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->greenText($data['description']) targeting BantenprovAnggaranSeeder::greenText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
72
                echo"\n";
73
                $this->orangeText('group_egovernment_id : ').$this->greenText($data['group_egovernment_id']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->orangeText('group_egovernment_id : ') targeting BantenprovAnggaranSeeder::orangeText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->greenText($data['group_egovernment_id']) targeting BantenprovAnggaranSeeder::greenText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
74
                echo"\n";
75
                $this->orangeText('sector_egovernment_id : ').$this->greenText($data['sector_egovernment_id']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->greenText($data['sector_egovernment_id']) targeting BantenprovAnggaranSeeder::greenText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->orangeText('sector_egovernment_id : ') targeting BantenprovAnggaranSeeder::orangeText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
76
                echo"\n";
77
                $this->orangeText('link : ').$this->greenText($data['link']);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->orangeText('link : ') targeting BantenprovAnggaranSeeder::orangeText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->greenText($data['link']) targeting BantenprovAnggaranSeeder::greenText() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
                echo"\n";
79
                echo "============[DATA]============\n\n";
80
            }
81
            
82
        }
83
84
        $this->greenText('[ SEEDER DONE ]');
85
        echo"\n\n";
86
    }
87
88
    /* text color: orange */
89
    protected function orangeText($text)
90
    {    
91
        printf($this->ORANGE.$text.$this->NC);
92
    }
93
94
    /* text color: green */
95
    protected function greenText($text)
96
    {    
97
        printf($this->GRN.$text.$this->NC);
98
    }
99
100
    /* function read CSV file */
101
    protected function readCSV()
102
    {
103
        /* Silahkan di rubah sesuai struktur file csv */
104
        $file = fopen(database_path("seeds/".$this->fileName), "r");
105
        $all_data = array();
106
        $row = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $row is dead and can be removed.
Loading history...
107
        while(($data = fgetcsv($file, 1000, ",")) !== FALSE){            
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $handle of fgetcsv() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
        while(($data = fgetcsv(/** @scrutinizer ignore-type */ $file, 1000, ",")) !== FALSE){            
Loading history...
108
            $all_data[] = ['user_id' 				=> $data[0], 
109
                            'label' 				=> $data[1],
110
                            'description' 			=> $data[2],
111
                            'group_egovernment_id' 	=> $data[3],
112
                            'sector_egovernment_id' => $data[4],
113
                            'link'                  => $data[5],
114
                        ];
115
        }        
116
        fclose($file);
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

116
        fclose(/** @scrutinizer ignore-type */ $file);
Loading history...
117
118
        return  $all_data;
119
    }
120
}
121
122