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

Base::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.576

Importance

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