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

Base   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 47
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

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