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

ImportConfiguration   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 79.31%

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 11
c 7
b 1
f 0
lcom 1
cbo 2
dl 0
loc 77
ccs 23
cts 29
cp 0.7931
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A setSourceStorageSelection() 0 6 1
A getSourceStorageSelection() 0 4 1
A setImporterId() 0 10 2
A toArray() 0 10 2
A toRun() 0 4 1
A getImporterId() 0 4 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