GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Queue   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 96
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A enqueue() 0 12 1
A dequeuePlain() 0 16 2
A dequeue() 0 12 2
A count() 0 4 1
A clear() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the PHPMongo package.
5
 *
6
 * (c) Dmytro Sokil <[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 Sokil\Mongo;
13
14
class Queue implements \Countable
15
{
16
    /**
17
     *
18
     * @var \Sokil\Mongo\Collection
19
     */
20
    private $collection;
21
    
22
    public function __construct(Database $database, $channel)
23
    {
24
        $this->collection = $database
25
            ->getCollection($channel)
26
            ->disableDocumentPool();
27
    }
28
    
29
    /**
30
     * Add item to queue
31
     *
32
     * @param mixed $payload data to send
33
     * @param int $priority more priority num give quicker getting from queue
34
     * @return \Sokil\Mongo\Queue
35
     */
36
    public function enqueue($payload, $priority = 0)
37
    {
38
        $this->collection
39
            ->createDocument(array(
40
                'payload'   => $payload,
41
                'priority'  => (int) $priority,
42
                'datetime'  => new \MongoDate,
43
            ))
44
            ->save();
45
        
46
        return $this;
47
    }
48
    
49
    /**
50
     * Get item from queue as is
51
     *
52
     * @return mixed
53
     */
54
    public function dequeuePlain()
55
    {
56
        $document = $this->collection
57
            ->find()
58
            ->sort(array(
59
                'priority' => -1,
60
                'datetime' => 1,
61
            ))
62
            ->findAndRemove();
63
        
64
        if (!$document) {
65
            return null;
66
        }
67
        
68
        return $document->get('payload');
69
    }
70
    
71
    /**
72
     * Get item from queue as Structure if array put into queue
73
     *
74
     * @return mixed|\Sokil\Mongo\Structure
75
     */
76
    public function dequeue()
77
    {
78
        $value = $this->dequeuePlain();
79
        if (!is_array($value)) {
80
            return $value;
81
        }
82
83
        $structure = new Structure();
84
        $structure->mergeUnmodified($value);
85
86
        return $structure;
87
    }
88
    
89
    /**
90
     * Get number of elements in queue
91
     *
92
     * @return int
93
     */
94
    public function count()
95
    {
96
        return count($this->collection);
97
    }
98
    
99
    /**
100
     * Clear queue
101
     *
102
     * @return \Sokil\Mongo\Queue
103
     */
104
    public function clear()
105
    {
106
        $this->collection->delete();
107
        return $this;
108
    }
109
}
110