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.

BatchProducer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 8 1
B produce() 0 23 6
A flush() 0 5 1
1
<?php
2
3
namespace AmqpWorkers;
4
5
use PhpAmqpLib\Connection\AbstractConnection;
6
7
/**
8
 * BatchProducer treats given message as a list of messages and send them to RabbitMQ channel
9
 *
10
 * @package AmqpWorkers
11
 * @author Alex Panshin <[email protected]>
12
 * @since 1.0
13
 */
14
class BatchProducer extends Producer
15
{
16
    private $limit = 0;
17
    private $queued = 0;
18
19
    public static function factory(AbstractConnection $connection, $limit = 100)
20
    {
21
        /** @var BatchProducer $producer */
22
        $producer = parent::factory($connection);
23
        $producer->limit = $limit;
24
25
        return $producer;
26
    }
27
28
    /**
29
     * @param array|\Traversable $messages
30
     * @throws \AmqpWorkers\Exception\ProducerNotProperlyConfigured
31
     */
32
    public function produce($messages)
33
    {
34
        $this->selfCheck();
35
36
        $channel = $this->getChannel();
37
        foreach ($messages as $payload) {
38
            if ($this->isExchange()) {
39
                $channel->batch_basic_publish($this->createMessage($payload), $this->exchange->getName());
40
            } else {
41
                $channel->batch_basic_publish($this->createMessage($payload), '', $this->queue->getName());
42
            }
43
44
            $this->queued++;
45
46
            if ($this->limit && $this->limit <= $this->queued) {
47
                $this->flush();
48
            }
49
        }
50
51
        if ($this->queued) {
52
            $this->flush();
53
        }
54
    }
55
56
    protected function flush()
57
    {
58
        $this->getChannel()->publish_batch();
59
        $this->queued = 0;
60
    }
61
}
62