Passed
Push — main ( 492649...1b3827 )
by De Cramer
07:40
created

ChainWorkDirManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
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
}