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

Base   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 39
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
validateSyntax() 0 1 ?
A __construct() 0 18 3
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