DataAggregate::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Adapter\Transaction;
11
12
/**
13
 * Holds data for transaction objects.
14
 */
15
class DataAggregate implements \IteratorAggregate
16
{
17
    /**
18
     * @var \Iterator Data iterator
19
     */
20
    protected $iterator;
21
22
    /**
23
     * @var mixed Original data
24
     */
25
    protected $originalData;
26
27
    /**
28
     * @param mixed $data Original data
29
     */
30 25
    public function __construct($data)
31
    {
32 25
        $this->setData($data);
33 25
    }
34
35
    /**
36
     * Returns original data.
37
     *
38
     * @return mixed Original data
39
     */
40 8
    public function getData()
41
    {
42 8
        return $this->originalData;
43
    }
44
45
    /**
46
     * Assigns data to the aggregate.
47
     *
48
     * @param mixed $data
49
     */
50 21
    public function setData($data)
51
    {
52 21
        $this->originalData = $data;
53
54 21
        if ($data instanceof \Iterator) {
55 2
            $this->iterator = $data;
56 2
        }
57 21
        elseif (is_array($data)) {
58 21
            $this->iterator = new \ArrayIterator($data);
59 21
        }
60
        else {
61 2
            $this->iterator = new \ArrayIterator(array($data));
62
        }
63 21
    }
64
65
    /**
66
     * Returns iterator with associated data.
67
     *
68
     * If the data aggregate was initialized with an array, an \ArrayIterator will be returned.
69
     *
70
     * @return \Iterator Data iterator
71
     */
72 9
    public function getIterator()
73
    {
74 9
        return $this->iterator;
75
    }
76
}
77