Completed
Push — master ( 6391fe...b20865 )
by Akihito
02:23
created

Queue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

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