OutboxMessageConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 46
ccs 25
cts 25
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDatabaseArray() 0 15 3
A toDatabaseArray() 0 17 2
1
<?php
2
namespace PSB\Persistence\Doctrine1\Outbox;
3
4
5
use PSB\Core\Outbox\OutboxMessage;
6
use PSB\Core\Outbox\OutboxTransportOperation;
7
8
class OutboxMessageConverter
9
{
10
    /**
11
     * @param array $dataArray
12
     *
13
     * @return OutboxMessage
14
     */
15 2
    public function fromDatabaseArray(array $dataArray)
16
    {
17 2
        $transportOperationsAsArrays = json_decode($dataArray['transport_operations'] ?: '[]', true);
18 2
        $transportOperationsAsObjects = [];
19 2
        foreach ($transportOperationsAsArrays as $transportOperation) {
20 1
            $transportOperationsAsObjects[] = new OutboxTransportOperation(
21 1
                $transportOperation['message_id'],
22 1
                $transportOperation['options'],
23 1
                $transportOperation['body'],
24 1
                $transportOperation['headers']
25 1
            );
26 2
        }
27
28 2
        return new OutboxMessage($dataArray['message_id'], $transportOperationsAsObjects);
29
    }
30
31
    /**
32
     * @param OutboxMessage $message
33
     *
34
     * @return array
35
     */
36 1
    public function toDatabaseArray(OutboxMessage $message)
37
    {
38 1
        $transportOperations = [];
39 1
        foreach ($message->getTransportOperations() as $transportOperation) {
40 1
            $transportOperations[] = [
41 1
                'message_id' => $transportOperation->getMessageId(),
42 1
                'body' => $transportOperation->getBody(),
43 1
                'headers' => $transportOperation->getHeaders(),
44 1
                'options' => $transportOperation->getOptions()
45 1
            ];
46 1
        }
47
48
        return [
49 1
            'message_id' => $message->getMessageId(),
50 1
            'transport_operations' => json_encode($transportOperations)
51 1
        ];
52
    }
53
}
54