ExceptionalQueue::pop()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue;
13
14
class ExceptionalQueue implements Queue
15
{
16
    /**
17
     * @var Queue
18
     */
19
    private $queue;
20
21 12
    public function __construct(Queue $queue)
22
    {
23 12
        $this->queue = $queue;
24 12
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 3
    public function push($item, $eta = null)
30
    {
31
        $this->exceptional(function () use ($item, $eta) {
32 3
            $this->queue->push($item, $eta);
33 3
        });
34 1
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 3
    public function pop()
40
    {
41
        return $this->exceptional(function () {
42 3
            return $this->queue->pop();
43 3
        });
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 3
    public function count()
50
    {
51
        return $this->exceptional(function () {
52 3
            return $this->queue->count();
53 3
        });
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function clear()
60
    {
61 3
        $this->exceptional(function () {
62 3
            $this->queue->clear();
63 3
        });
64 1
    }
65
66
    /**
67
     * @param \Closure $func The function to execute.
68
     *
69
     * @return mixed
70
     *
71
     * @throws QueueException
72
     */
73 12
    protected function exceptional(\Closure $func)
74
    {
75
        try {
76 12
            $result = $func();
77 12
        } catch (QueueException $e) {
78 4
            throw $e;
79 4
        } catch (\Exception $e) {
80 4
            throw new QueueException($this->queue, $e->getMessage(), 0, $e);
81
        }
82
83 4
        return $result;
84
    }
85
}
86