Completed
Pull Request — master (#41)
by Gawain
03:04
created

FlushableQueue::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Genkgo\Mail\Queue;
4
5
use Genkgo\Mail\Exception\EmptyQueueException;
6
use Genkgo\Mail\MessageInterface;
7
8
/**
9
 * Class FlushableQueue
10
 * @package Genkgo\Mail\Queue
11
 */
12
final class FlushableQueue implements QueueInterface
13
{
14
    /**
15
     * @var QueueInterface
16
     */
17
    private $decoratedQueue;
18
19 3
    public function __construct(QueueInterface $queue)
20
    {
21 3
        $this->decoratedQueue = $queue;
22 3
    }
23
24 1
    public function flush(): int
25
    {
26 1
        $count = 0;
27
        try {
28 1
            while ($this->decoratedQueue->fetch()) {
29 1
                ++$count;
30
            }
31 1
        } catch (EmptyQueueException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
32
        }
33
34 1
        return $count;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function store(MessageInterface $message): void
41
    {
42 1
        $this->decoratedQueue->store($message);
43 1
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 1
    public function fetch(): MessageInterface
49
    {
50 1
        return $this->decoratedQueue->fetch();
51
    }
52
}
53