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

FlushableQueue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A flush() 0 12 3
A store() 0 4 1
A fetch() 0 4 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