BaseImport::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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
}