PerExecutionContextFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A get() 0 12 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Oliverde8\Component\PhpEtl;
5
6
use Oliverde8\Component\PhpEtl\Factory\FileSystemFactoryInterface;
7
use Oliverde8\Component\PhpEtl\Factory\LoggerFactoryInterface;
8
use Oliverde8\Component\PhpEtl\Model\ExecutionContext;
9
use Oliverde8\Component\PhpEtl\Model\ExecutionInterface;
10
use Oliverde8\Component\PhpEtl\Model\PerExecutionExecutionContext;
11
12
class PerExecutionContextFactory implements ExecutionContextFactoryInterface
13
{
14
    private ChainWorkDirManager $dirManager;
15
16
    private FileSystemFactoryInterface $fileSystemFactory;
17
18
    private LoggerFactoryInterface $loggerFactory;
19
20
    public function __construct(
21
        ChainWorkDirManager $dirManager,
22
        FileSystemFactoryInterface $fileSystemFactory,
23
        LoggerFactoryInterface $loggerFactory
24
    ) {
25
        $this->dirManager = $dirManager;
26
        $this->fileSystemFactory = $fileSystemFactory;
27
        $this->loggerFactory = $loggerFactory;
28
    }
29
30
31
    public function get(array $parameters): ExecutionContext
32
    {
33
        $execution = $parameters['etl']['execution'] ?? null;
34
        if (!$execution instanceof ExecutionInterface) {
35
            throw new \LogicException("Etl execution needs to have a unique execution object of type ExecutionInterface as per Execution Context is used");
36
        }
37
38
        $fileSystem = $this->fileSystemFactory->get($execution);
39
        $logger = $this->loggerFactory->get($execution);
40
        $workDir = $this->dirManager->getLocalTmpWorkDir($execution);
41
42
        return new PerExecutionExecutionContext($parameters, $fileSystem, $logger, $workDir);
43
    }
44
}