Completed
Push — master ( e03b67...e42da4 )
by
unknown
03:39 queued 10s
created

AbstractFolderExtrator::getFolderToExtract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Smart\EtlBundle\Extractor;
4
5
use Symfony\Component\Finder\Finder;
6
use Symfony\Component\Finder\SplFileInfo;
7
8
/**
9
 * Nicolas Bastien <[email protected]>
10
 */
11
abstract class AbstractFolderExtrator extends AbstractExtractor
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $folderToExtract;
17
18
    /**
19
     * @var string
20
     */
21
    abstract protected function getFileExtension();
22
23
    /**
24
     * @param  string $filepath
25
     * @return mixed
26
     */
27
    abstract protected function extractFileContent($filepath);
28
29
    /**
30
     * @return string
31
     */
32
    public function getFolderToExtract()
33
    {
34
        return $this->folderToExtract;
35
    }
36
37
    /**
38
     * @param string $folderToExtract
39
     */
40 6
    public function setFolderToExtract($folderToExtract)
41
    {
42 6
        $this->folderToExtract = $folderToExtract;
43 6
    }
44
45 5
    protected function check()
46
    {
47 5
        if (!is_dir($this->folderToExtract)) {
48
            throw new \BadMethodCallException('Invalid folder to extract : ' . $this->folderToExtract);
49
        }
50 5
    }
51
    
52
    /**
53
     * @param  string $extension
54
     * @return array
55
     */
56 5
    protected function getFiles($extension)
57
    {
58 5
        $finder = new Finder();
59 5
        $finder->in($this->folderToExtract);
60 5
        $files = [];
61
        /* @var SplFileInfo $file */
62 5
        foreach ($finder->files()->name('*.' . $extension) as $file) {
63 5
            $files[] = substr($file->getFilename(), 0, -(strlen($extension)+1));
64
        }
65
66 5
        return array_combine($files, $files);
67
    }
68
}
69