Completed
Push — master ( 745a49...f028fe )
by Markus
04:58
created

ImportConfiguration::setSourceStorageSelection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace Mathielen\ImportEngine\ValueObject;
3
4
class ImportConfiguration
5
{
6
7
    private $importerId = null;
8
9
    /**
10
     * @var StorageSelection
11
     */
12
    private $sourceStorageSelection;
13
14 16
    public function __construct(StorageSelection $sourceStorageSelection=null, $importerId=null)
15
    {
16 16
        if ($importerId) {
17 1
            $this->setImporterId($importerId);
18 1
        }
19 16
        if ($sourceStorageSelection) {
20 1
            $this->setSourceStorageSelection($sourceStorageSelection);
21 1
        }
22 16
    }
23
24
    /**
25
     * @return ImportConfiguration
26
     */
27 1
    public function setSourceStorageSelection(StorageSelection $sourceStorageSelection)
28
    {
29 1
        $this->sourceStorageSelection = $sourceStorageSelection;
30
31 1
        return $this;
32
    }
33
34
    /**
35
     * @return StorageSelection
36
     */
37
    public function getSourceStorageSelection()
38
    {
39
        return $this->sourceStorageSelection;
40
    }
41
42
    /**
43
     * @return ImportConfiguration
44
     */
45 1
    public function setImporterId($importerId)
46
    {
47 1
        if (empty($importerId)) {
48
            throw new \InvalidArgumentException("importerId must be given");
49
        }
50
51 1
        $this->importerId = $importerId;
52
53 1
        return $this;
54
    }
55
56 1
    public function getImporterId()
57
    {
58 1
        return $this->importerId;
59
    }
60
61 2
    public function toArray()
62
    {
63
        return array(
64 2
            'importerid' => $this->importerId,
65 2
            'sourcestorageselection' => $this->sourceStorageSelection?array(
66
                'name' => $this->sourceStorageSelection->getName(),
67
                'id' => $this->sourceStorageSelection->getId()
68
            ):null
69 2
        );
70
    }
71
72
    /**
73
     * @return ImportRun
74
     */
75 8
    public function toRun($createdBy=null)
76
    {
77 8
        return new ImportRun($this, $createdBy);
78
    }
79
80
}
81