Passed
Push — master ( 62919d...1f65fa )
by Iman
04:23
created

ImportData   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getImportData() 0 34 6
A postDoImportChunk() 0 13 3
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 '.CRUDBooster::getCurrentModule()->name;
0 ignored issues
show
Bug introduced by
The type Crocodicstudio\Crudboost...BController\CRUDBooster was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
        if (! request('file') || request('import')) {
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'));
0 ignored issues
show
Bug introduced by
It seems like request('file') can also be of type array; however, parameter $data of base64_decode() does only seem to accept string, 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

24
        $file = 'storage'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.base64_decode(/** @scrutinizer ignore-type */ request('file'));
Loading history...
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));
29
30
        $import_column = [];
31
        foreach ($rows as $value) {
32
            $a = [];
33
            foreach ($value as $k => $v) {
34
                $a[] = $k;
35
            }
36
            if (count($a)) {
37
                $import_column = $a;
38
            }
39
            break;
40
        }
41
42
        $data['table_columns'] = DB::getSchemaBuilder()->getColumnListing($this->table);
43
        $data['data_import_column'] = $import_column;
44
45
        return $this->cbView('crudbooster::import', $data);
46
    }
47
48
    public function postDoImportChunk()
49
    {
50
        $import = app(IndexImport::class);
51
        $this->genericLoader();
52
        $fileMD5 = md5(request('file'));
0 ignored issues
show
Bug introduced by
It seems like request('file') can also be of type array; however, parameter $str of md5() does only seem to accept string, 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

52
        $fileMD5 = md5(/** @scrutinizer ignore-type */ request('file'));
Loading history...
53
54
        if (request('file') && request('resume') == 1) {
55
            return $import->handleImportProgress($fileMD5);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $import->handleImportProgress($fileMD5) targeting Crocodicstudio\Crudboost...:handleImportProgress() 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...
56
        }
57
58
        $import->InsertToDB($fileMD5, $this->table, $this->titleField);
59
60
        return response()->json(['status' => true]);
0 ignored issues
show
Bug introduced by
The method json() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\Response or Illuminate\Http\JsonResponse or Illuminate\Http\RedirectResponse. ( 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 response()->/** @scrutinizer ignore-call */ json(['status' => true]);
Loading history...
Bug introduced by
Are you sure the usage of response()->json(array('status' => true)) targeting ImanGhafoori\Terminator\Responder::json() 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...
61
    }
62
63
64
}