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

AbstractFolderExtrator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 47
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFolderToExtract() 0 4 1
A setFolderToExtract() 0 4 1
A check() 0 6 2
A getFiles() 0 12 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
    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