Completed
Push — master ( f32f25...d91936 )
by John
03:08
created

Producer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 3
c 4
b 2
f 1
lcom 1
cbo 3
dl 0
loc 36
ccs 21
cts 21
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B publish() 0 24 3
1
<?php
2
/**
3
 * The MIT License
4
 *
5
 * Copyright (c) 2010 Alvaro Videla
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 *
25
 * PHP version 5.3
26
 *
27
 * @category   Thumper
28
 * @package    Thumper
29
 * @author     Alvaro Videla
30
 * @copyright  2010 Alvaro Videla. All rights reserved.
31
 * @license    MIT http://opensource.org/licenses/MIT
32
 * @link       https://github.com/videlalvaro/Thumper
33
 */
34
namespace Thumper;
35
36
use PhpAmqpLib\Message\AMQPMessage;
37
38
class Producer extends BaseAmqp
39
{
40
    /**
41
     * @var bool
42
     */
43
    protected $exchangeReady = false;
44
45
    /**
46
     * @param string $messageBody
47
     * @param string $routingKey
48
     */
49 25
    public function publish($messageBody, $routingKey = '')
50
    {
51 25
        if (!$this->exchangeReady) {
52
            //declare a durable non autodelete exchange
53 25
            $this->channel->exchange_declare(
54 25
                $this->exchangeOptions['name'],
55 25
                $this->exchangeOptions['type'],
56 25
                false,
57 25
                true,
58 5
                false
59 20
            );
60 15
            $this->exchangeReady = true;
61 12
        }
62
63 15
        $message = new AMQPMessage(
64 12
            $messageBody,
65 15
            array('content_type' => 'text/plain', 'delivery_mode' => 2)
66 12
        );
67 15
        $this->channel->basic_publish(
68 12
            $message,
69 15
            $this->exchangeOptions['name'],
70 15
            !empty($routingKey) ? $routingKey : $this->routingKey
71 12
        );
72 5
    }
73
}
74