Completed
Pull Request — master (#6)
by
unknown
02:04
created

Base::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 10
cp 0.9
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
crap 3.009
1
<?php
2
3
namespace Dyrynda\Artisan\BulkImport\Handlers;
4
5
use SplFileInfo;
6
use Dyrynda\Artisan\Exceptions\ImportFileException;
7
use Dyrynda\Artisan\BulkImport\BulkImportFileHandler;
8
9
abstract class Base implements BulkImportFileHandler
10
{
11
    protected $file;
12
    protected $fields;
13
    protected $filePath;
14
    protected $fileHandle;
15
16
    /**
17
     * Base constructor.
18
     * @param $filePath
19
     *
20
     * @throws \Dyrynda\Artisan\Exceptions\ImportFileException
21
     */
22 16
    public function __construct(SplFileInfo $file)
23
    {
24 16
        $this->file = $file;
25
26 16
        $this->filePath = $file->getPathname();
27
28 16
        if (! $this->file->getExtension()) {
29
            throw ImportFileException::noExtension();
30
        }
31
32 16
        if (! $this->file->isFile()) {
33 1
            throw ImportFileException::notExist($this->filePath);
34
        }
35
36 15
        $this->fileHandle = $this->file->openFile();
37
38 15
        $this->validateSyntax();
39 12
    }
40
41
    /**
42
     * Checks file for valid syntax.
43
     *
44
     * @return void
45
     * @throws \Dyrynda\Artisan\Exceptions\ImportFileException
46
     */
47
    abstract protected function validateSyntax();
48
49
    /**
50
     * Get the info from the file.
51
     *
52
     * @return array
53
     */
54
    abstract public function getData();
55
}
56