Completed
Push — master ( 922e8a...cfbc00 )
by Akihito
02:15
created

Queue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 2
cbo 2
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A enqueue() 0 13 3
A dequeue() 0 11 2
1
<?php
2
namespace Ackintosh\Snidel\Task;
3
4
use Ackintosh\Snidel\AbstractQueue;
5
use Ackintosh\Snidel\Task\Formatter;
6
7
class Queue extends AbstractQueue
8
{
9
    /**
10
     * @param   \Ackintosh\Snidel\Task  $task
11
     * @return  void
12
     * @throws  RuntimeException
13
     */
14
    public function enqueue($task)
15
    {
16
        $this->queuedCount++;
17
18
        $serialized = Formatter::serialize($task);
19
        if ($this->isExceedsLimit($serialized)) {
20
            throw new \RuntimeException('the task exceeds the message queue limit.');
21
        }
22
23
        if (!$this->sendMessage($serialized)) {
24
            throw new \RuntimeException('failed to enqueue task.');
25
        }
26
    }
27
28
    /**
29
     * @return  \Ackintosh\Snidel\Task
30
     * @throws  \RuntimeException
31
     */
32
    public function dequeue()
33
    {
34
        $this->dequeuedCount++;
35
        try {
36
            $serializedTask = $this->receiveMessage();
37
        } catch (\RuntimeException $e) {
38
            throw new \RuntimeException('failed to dequeue task');
39
        }
40
41
        return Formatter::unserialize($serializedTask);
42
    }
43
}
44