BaseImport   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 41
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A importFromFile() 0 3 1
A setModel() 0 5 1
A __construct() 0 3 1
A model() 0 8 2
1
<?php
2
namespace Distilleries\Expendable\Imports;
3
4
use Distilleries\Expendable\Contracts\ImportContract;
5
use Maatwebsite\Excel\Concerns\Importable;
6
use Maatwebsite\Excel\Concerns\ToModel;
7
use Maatwebsite\Excel\Concerns\WithHeadingRow;
8
9
class BaseImport implements ToModel, WithHeadingRow, ImportContract
10
{
11
    use Importable;
0 ignored issues
show
introduced by
The trait Maatwebsite\Excel\Concerns\Importable requires some properties which are not provided by Distilleries\Expendable\Imports\BaseImport: $disk, $readerType, $filePath
Loading history...
12
13
    /**
14
     * @var \Distilleries\Expendable\Models\BaseModel
15
     */
16
    private $model;
17
18 4
    public function __construct($model)
19
    {
20 4
        $this->setModel($model);
21
    }
22
23 4
    public function importFromFile($filepath)
24
    {
25 4
        return $this->import($filepath);
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31 4
    public function model(array $row)
32
    {
33 4
        $data = [];
34 4
        foreach ($this->model->getFillable() as $value)
35
        {
36 4
            $data[$value] = $row[$value];
37
        }
38 4
        return new $this->model($data);
39
    }
40
41
    /**
42
     * @param mixed $model
43
     * @return $this
44
     */
45 4
    public function setModel($model)
46
    {
47 4
        $this->model = $model;
48
49 4
        return $this;
50
    }
51
}