Completed
Push — master ( 57351d...99d468 )
by Nicolas
15s queued 10s
created

AbstractFolderExtrator::getFolderToExtract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $folderToExtract;
17
18
    /**
19
     * @return string
20
     */
21
    public function getFolderToExtract()
22
    {
23
        return $this->folderToExtract;
24
    }
25
26
    /**
27
     * @param string $folderToExtract
28
     */
29 4
    public function setFolderToExtract($folderToExtract)
30
    {
31 4
        $this->folderToExtract = $folderToExtract;
32 4
    }
33
34 3
    protected function check()
35
    {
36 3
        if (!is_dir($this->folderToExtract)) {
37
            throw new \BadMethodCallException('Invalid folder to extract');
38
        }
39 3
    }
40
    
41
    /**
42
     * @param  string $extension
43
     * @return array
44
     */
45 3
    protected function getFiles($extension)
46
    {
47 3
        $finder = new Finder();
48 3
        $finder->in($this->folderToExtract);
49 3
        $files = [];
50
        /* @var SplFileInfo $file */
51 3
        foreach ($finder->files()->name('*.' . $extension) as $file) {
52 3
            $files[] = substr($file->getFilename(), 0, -(strlen($extension)+1));
53
        }
54
55 3
        return array_combine($files, $files);
56
    }
57
}
58