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

AbstractFolderExtrator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
ccs 13
cts 16
cp 0.8125
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 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