Doctrine2OutboxStorage::markAsDispatched()   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
namespace PSB\Persistence\Doctrine2\Outbox;
3
4
5
use PSB\Core\Outbox\OutboxMessage;
6
use PSB\Core\Outbox\OutboxStorageInterface;
7
8
class Doctrine2OutboxStorage implements OutboxStorageInterface
9
{
10
    /**
11
     * @var OutboxPersister
12
     */
13
    private $persister;
14
15
    /**
16
     * @var OutboxMessageConverter
17
     */
18
    private $messageConverter;
19
20
    /**
21
     * @var int
22
     */
23
    private $endpointId;
24
25
    /**
26
     * @param OutboxPersister        $persister
27
     * @param OutboxMessageConverter $messageConverter
28
     * @param int                    $endpointId
29
     */
30 8
    public function __construct(OutboxPersister $persister, OutboxMessageConverter $messageConverter, $endpointId)
31
    {
32 8
        $this->persister = $persister;
33 8
        $this->messageConverter = $messageConverter;
34 8
        $this->endpointId = $endpointId;
35 8
    }
36
37
    /**
38
     * Fetches the given message from the storage. It returns null if no message is found.
39
     *
40
     * @param string $messageId
41
     *
42
     * @return OutboxMessage|null
43
     */
44 2
    public function get($messageId)
45
    {
46 2
        $outboxRecord = $this->persister->get($this->endpointId, $messageId);
47 2
        if ($outboxRecord) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $outboxRecord of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
48 1
            return $this->messageConverter->fromDatabaseArray($outboxRecord);
49
        }
50 1
        return null;
51
    }
52
53
    /**
54
     * Stores the message to enable deduplication and re-dispatching of transport operations.
55
     * Throws an exception if a message with the same ID already exists.
56
     *
57
     * @param OutboxMessage $message
58
     *
59
     * @return void
60
     */
61 1
    public function store(OutboxMessage $message)
62
    {
63 1
        $outboxRecord = $this->messageConverter->toDatabaseArray($message);
64 1
        $this->persister->store($this->endpointId, $outboxRecord);
65 1
    }
66
67
    /**
68
     * @param string $messageId
69
     *
70
     * @return void
71
     */
72 1
    public function markAsDispatched($messageId)
73
    {
74 1
        $this->persister->markAsDispatched($this->endpointId, $messageId);
75 1
    }
76
77
    /**
78
     * Initiates the transaction
79
     *
80
     * @return void
81
     */
82 1
    public function beginTransaction()
83
    {
84 1
        $this->persister->beginTransaction();
85 1
    }
86
87
    /**
88
     * Commits the transaction
89
     *
90
     * @return void
91
     */
92 1
    public function commit()
93
    {
94 1
        $this->persister->commit();
95 1
    }
96
97
    /**
98
     * Rolls back the transaction
99
     *
100
     * @return void
101
     */
102 1
    public function rollBack()
103
    {
104 1
        $this->persister->rollBack();
105 1
    }
106
}
107