Passed
Push — master ( 0b19e6...20f332 )
by Mike
03:05
created

TransactionHandler::getTransactionArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
4
namespace Xervice\Redis\Transaction;
5
6
7
8
use Xervice\DataProvider\DataProvider\AbstractDataProvider;
9
10
class TransactionHandler implements TransactionHandlerInterface
11
{
12
    /**
13
     * @var \Xervice\Redis\Transaction\TransactionCollection
14
     */
15
    private $collection;
16
17
    /**
18
     * TransactionHandler constructor.
19
     *
20
     * @param \Xervice\Redis\Transaction\TransactionCollection $collection
21
     */
22 1
    public function __construct(\Xervice\Redis\Transaction\TransactionCollection $collection)
23
    {
24 1
        $this->collection = $collection;
25 1
    }
26
27
    /**
28
     * @param \Xervice\Redis\Transaction\TransactionInterface $transaction
29
     */
30 1
    public function addToCollection(TransactionInterface $transaction)
31
    {
32 1
        $this->collection->add($transaction);
33 1
    }
34
35 1
    public function clearCollection()
36
    {
37 1
        $this->collection->clear();
38 1
    }
39
40
    /**
41
     * @return array
42
     */
43 1
    public function getTransactionArray() : array
44
    {
45 1
        $transactionList = [];
46
47 1
        foreach ($this->collection as $transaction) {
48 1
            $transactionList[$transaction->getKey()] = $transaction->getDataProvider();
49
        }
50
51 1
        return $transactionList;
52
    }
53
}