Passed
Push — main ( 1b3827...987cb0 )
by De Cramer
03:06
created

ChainWorkDirManager::listFiles()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 4
nc 3
nop 1
1
<?php
2
3
4
namespace Oliverde8\PhpEtlBundle\Services;
5
6
7
use Oliverde8\PhpEtlBundle\Entity\EtlExecution;
8
use Symfony\Component\Filesystem\Exception\IOException;
9
use Symfony\Component\Filesystem\Filesystem;
10
11
class ChainWorkDirManager
12
{
13
    /** @var string  */
14
    protected $baseDir;
15
16
    /** @var Filesystem */
17
    protected $fileSystem;
18
19
    /**
20
     * ChainWorkDirManager constructor.
21
     * @param string $directory
22
     */
23
    public function __construct(string $baseDir, Filesystem $filesystem)
24
    {
25
        $this->baseDir = $baseDir;
26
        $this->fileSystem = $filesystem;
27
    }
28
29
    /**
30
     * @param EtlExecution $execution
31
     * @return string
32
     *
33
     * @throws IOException if directory can't be created.
34
     */
35
    public function getWorkDir(EtlExecution $execution): string
36
    {
37
        $dir = $this->baseDir . "/" . $execution->getStartTime()->format("y/m/d") . "/id-" . $execution->getId() . "/";
38
        $this->fileSystem->mkdir($dir);
39
40
        return $dir;
41
    }
42
43
    public function listFiles(EtlExecution $execution): array
44
    {
45
        $files = [];
46
        $dir = $this->getWorkDir($execution);
47
48
        $handle = opendir($dir);
49
        while (false !== ($entry = readdir($handle))) {
50
            if ($entry != "." && $entry != "..") {
51
                $files[] = $entry;
52
            }
53
        }
54
55
        return $files;
56
    }
57
}