Completed
Pull Request — master (#4)
by Nicolas
02:25
created

AbstractFolderExtrator::check()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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