Import::getSourceStorage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Mathielen\ImportEngine\Import;
4
5
use Mathielen\ImportEngine\Importer\Importer;
6
use Mathielen\ImportEngine\Importer\ImporterInterface;
7
use Mathielen\ImportEngine\Storage\StorageInterface;
8
use Mathielen\ImportEngine\Transformation\Transformation;
9
use Mathielen\ImportEngine\Mapping\Mappings;
10
use Mathielen\ImportEngine\ValueObject\ImportRun;
11
12
class Import
13
{
14
    /**
15
     * @var ImporterInterface
16
     */
17
    private $importer;
18
19
    /**
20
     * @var Transformation
21
     */
22
    private $transformation;
23
24
    /**
25
     * @var StorageInterface
26
     */
27
    private $sourceStorage;
28
29
    /**
30
     * @var Mappings
31
     */
32
    private $mappings;
33
34
    /**
35
     * @var ImportRun
36
     */
37
    private $importRun;
38
39
    /**
40
     * @return Import
41
     */
42 20
    public static function build(ImporterInterface $importer, StorageInterface $sourceStorage, ImportRun $importRun = null)
43
    {
44 20
        return new self($importer, $sourceStorage, $importRun);
45
    }
46
47 20
    public function __construct(ImporterInterface $importer, StorageInterface $sourceStorage, ImportRun $importRun = null)
48
    {
49 20
        if (!$importRun) {
50 12
            $importRun = new ImportRun();
51
        }
52
53 20
        $this->importer = $importer;
54 20
        $this->sourceStorage = $sourceStorage;
55 20
        $this->importRun = $importRun;
56 20
        $this->transformation = $importer->transformation();
57 20
    }
58
59
    /**
60
     * @return \Mathielen\ImportEngine\Importer\ImporterInterface
61
     */
62 15
    public function importer()
63
    {
64 15
        return $this->importer;
65
    }
66
67
    /**
68
     * @return Mappings
69
     */
70 18
    public function mappings()
71
    {
72 18
        if (!$this->mappings && $this->getSourceStorage()) {
73 18
            $this->mappings = $this->transformation->buildMapping($this->getSourceStorage()->reader());
74
        }
75
76 18
        return $this->mappings;
77
    }
78
79
    /**
80
     * @return \Mathielen\ImportEngine\Storage\StorageInterface
81
     */
82 11
    public function getTargetStorage()
83
    {
84 11
        return $this->importer->targetStorage();
85
    }
86
87
    /**
88
     * @return \Mathielen\ImportEngine\Storage\StorageInterface
89
     */
90 18
    public function getSourceStorage()
91
    {
92 18
        return $this->sourceStorage;
93
    }
94
95
    /**
96
     * @return ImportRun
97
     */
98 19
    public function getRun()
99
    {
100 19
        return $this->importRun;
101
    }
102
}
103