<commit_before><?php

namespace OldSound\RabbitMqBundle\RabbitMq;

use OldSound\RabbitMqBundle\RabbitMq\BaseAmqp;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;

class Producer extends BaseAmqp
{
    protected $declared = false;

    public function exchangeDeclare()
    {
        $this->ch->exchange_declare(
            $this->exchangeOptions['name'],
            $this->exchangeOptions['type'],
            $this->exchangeOptions['passive'],
            $this->exchangeOptions['durable'],
            $this->exchangeOptions['auto_delete'],
            $this->exchangeOptions['internal']);

        $this->declared = true;

        if (('' != $this->queueOptions['name']) && (null !== $this->queueOptions['name'])) {
            list($queueName, ,) = $this->ch->queue_declare($this->queueOptions['name'], $this->queueOptions['passive'],
                                                                   $this->queueOptions['durable'], $this->queueOptions['exclusive'],
                                                                   $this->queueOptions['auto_delete'], $this->queueOptions['nowait'],
                                                                   $this->queueOptions['arguments'], $this->queueOptions['ticket']);

            $this->ch->queue_bind($queueName, $this->exchangeOptions['name'], $this->routingKey);
        }
    }

    public function publish($msgBody, $routingKey = '')
    {
        if (!$this->declared) {
            $this->exchangeDeclare();
        }
        $msg = new AMQPMessage($msgBody, array('content_type' => 'text/plain', 'delivery_mode' => 2));
        $this->ch->basic_publish($msg, $this->exchangeOptions['name'], $routingKey);
    }
}<commit_msg>moved queue setup to its own method<commit_after><?php

namespace OldSound\RabbitMqBundle\RabbitMq;

use OldSound\RabbitMqBundle\RabbitMq\BaseAmqp;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;

class Producer extends BaseAmqp
{
    protected $exchangeDeclared = false;
    protected $queueDeclared = false;

    public function exchangeDeclare()
    {
        $this->ch->exchange_declare(
            $this->exchangeOptions['name'],
            $this->exchangeOptions['type'],
            $this->exchangeOptions['passive'],
            $this->exchangeOptions['durable'],
            $this->exchangeOptions['auto_delete'],
            $this->exchangeOptions['internal']);

        $this->exchangeDeclared = true;
    }

    public function queueDeclare()
    {
        if (null !== $this->queueOptions['name']) {
            list($queueName, ,) = $this->ch->queue_declare($this->queueOptions['name'], $this->queueOptions['passive'],
                                                                   $this->queueOptions['durable'], $this->queueOptions['exclusive'],
                                                                   $this->queueOptions['auto_delete'], $this->queueOptions['nowait'],
                                                                   $this->queueOptions['arguments'], $this->queueOptions['ticket']);

            $this->ch->queue_bind($queueName, $this->exchangeOptions['name'], $this->routingKey);

            $this->queueDeclared = true;
        }
    }

    public function setupProducer()
    {
        if (!$this->exchangeDeclared) {
            $this->exchangeDeclare();
        }

        if (!$this->queueDeclared) {
            $this->queueDeclare();
        }
    }

    public function publish($msgBody, $routingKey = '')
    {
        $this->setupProducer();

        $msg = new AMQPMessage($msgBody, array('content_type' => 'text/plain', 'delivery_mode' => 2));
        $this->ch->basic_publish($msg, $this->exchangeOptions['name'], $routingKey);
    }
}
{'fraction_non_alphanumeric': 0.15230408747721946, 'fraction_numerical': 0.000520697734964853, 'mean_word_length': 2.2531752751905163, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3059523', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1010, 'n_words': 146}