ChainWorkDirManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 4
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLocalTmpWorkDir() 0 10 2
1
<?php
2
3
namespace Oliverde8\PhpEtlBundle\Services;
4
5
use Oliverde8\PhpEtlBundle\Entity\EtlExecution;
6
use Symfony\Component\Filesystem\Exception\IOException;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
class ChainWorkDirManager
10
{
11
    private string $tmpBaseDir;
12
13
    private Filesystem $tmpFileSystem;
14
15
    public function __construct(string $tmpBaseDir, Filesystem $tmpFileSystem)
16
    {
17
        $this->tmpBaseDir = $tmpBaseDir;
18
        $this->tmpFileSystem = $tmpFileSystem;
19
    }
20
21
    /**
22
     * @param EtlExecution $execution
23
     * @param bool $createIfMissing
24
     * @return string
25
     *
26
     * @throws IOException if directory can't be created.
27
     */
28
    public function getLocalTmpWorkDir(EtlExecution $execution, $createIfMissing = true): string
29
    {
30
        $currentTime = $execution->getCreateTime()->format("y/m/d");
31
        $dir = $this->tmpBaseDir . "/" . $currentTime . "/id-" . $execution->getId();
32
33
        if ($createIfMissing) {
34
            $this->tmpFileSystem->mkdir($dir);
35
        }
36
37
        return $dir;
38
    }
39
}