Passed
Pull Request — master (#30)
by De Cramer
08:52
created

LocalFileSystemFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Oliverde8\Component\PhpEtl\Factory;
5
6
use Oliverde8\Component\PhpEtl\ChainWorkDirManager;
7
use Oliverde8\Component\PhpEtl\Model\ExecutionInterface;
8
use Oliverde8\Component\PhpEtl\Model\File\FileSystemInterface;
9
use Oliverde8\Component\PhpEtl\Model\File\LocalFileSystem;
10
11
class LocalFileSystemFactory implements FileSystemFactoryInterface
12
{
13
    private ChainWorkDirManager $chainWorkDirManager;
14
15
    /** @var FileSystemInterface[] */
16
    private array $fileSystems;
17
18
    public function __construct(ChainWorkDirManager $chainWorkDirManager)
19
    {
20
        $this->chainWorkDirManager = $chainWorkDirManager;
21
    }
22
23
    public function get(ExecutionInterface $execution): FileSystemInterface
24
    {
25
        if (!isset($this->fileSystems[$execution->getId()])) {
26
            $this->fileSystems[$execution->getId()] = new LocalFileSystem($this->chainWorkDirManager->getLocalTmpWorkDir($execution));
27
        }
28
29
        return $this->fileSystems[$execution->getId()];
30
    }
31
}