Passed
Pull Request — master (#1093)
by Iman
06:06
created

ImportData::postDoImportChunk()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\controllers\CBController;
4
5
use crocodicstudio\crudbooster\controllers\Helpers\IndexImport;
6
use Illuminate\Support\Facades\DB;
7
use Maatwebsite\Excel\Facades\Excel;
8
use Illuminate\Support\Facades\Route;
9
10
trait ImportData
11
{
12
    public function getImportData()
13
    {
14
        $this->genericLoader();
0 ignored issues
show
Bug introduced by
It seems like genericLoader() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

14
        $this->/** @scrutinizer ignore-call */ 
15
               genericLoader();
Loading history...
15
16
        $data = [];
17
        $data['page_menu'] = Route::getCurrentRoute()->getActionName();
18
        $data['page_title'] = 'Import Data '.CB::getCurrentModule()->name;
19
20
        if (! request('file') || request('import')) {
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

20
        if (! /** @scrutinizer ignore-call */ request('file') || request('import')) {
Loading history...
21
            return $this->cbView('crudbooster::import', $data);
0 ignored issues
show
Bug introduced by
It seems like cbView() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
            return $this->/** @scrutinizer ignore-call */ cbView('crudbooster::import', $data);
Loading history...
22
        }
23
24
        $file = 'storage'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.base64_decode(request('file'));
25
        $rows = Excel::load($file, function ($reader) {
0 ignored issues
show
Unused Code introduced by
The parameter $reader is not used and could be removed. ( Ignorable by Annotation )

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

25
        $rows = Excel::load($file, function (/** @scrutinizer ignore-unused */ $reader) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
        })->get();
27
28
        session()->put('total_data_import', count($rows));
0 ignored issues
show
Bug introduced by
The function session was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

28
        /** @scrutinizer ignore-call */ 
29
        session()->put('total_data_import', count($rows));
Loading history...
29
30
        $data_import_column = [];
31
        foreach ($rows as $value) {
32
            $a = [];
33
            foreach ($value as $k => $v) {
34
                $a[] = $k;
35
            }
36
            if (count($a)) {
37
                $data_import_column = $a;
38
            }
39
            break;
40
        }
41
42
        $data['table_columns'] = DB::getSchemaBuilder()->getColumnListing($this->table);
43
        $data['data_import_column'] = $data_import_column;
44
45
        return $this->cbView('crudbooster::import', $data);
46
    }
47
48
    public function postDoImportChunk()
49
    {
50
        $import = app(IndexImport::class);
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

50
        $import = /** @scrutinizer ignore-call */ app(IndexImport::class);
Loading history...
51
        $this->genericLoader();
52
        $fileMD5 = md5(request('file'));
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

52
        $fileMD5 = md5(/** @scrutinizer ignore-call */ request('file'));
Loading history...
53
54
        if (request('file') && request('resume') == 1) {
55
            return $import->handleImportProgress($fileMD5);
56
        }
57
58
        $import->InsertToDB($fileMD5, $this->table, $this->title_field);
59
60
        return response()->json(['status' => true]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

60
        return /** @scrutinizer ignore-call */ response()->json(['status' => true]);
Loading history...
61
    }
62
63
64
}