QueueSession   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 68
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A send() 0 4 1
A createSender() 0 4 1
A getId() 0 4 1
1
<?php
2
3
/**
4
 * AppserverIo\Messaging\QueueSession
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/messaging
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Messaging;
22
23
use AppserverIo\Psr\Pms\QueueInterface;
24
use AppserverIo\Psr\Pms\MessageInterface;
25
26
/**
27
 * The queue session implementation.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2015 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/appserver-io/messaging
33
 * @link      http://www.appserver.io
34
 */
35
class QueueSession
36
{
37
38
    /**
39
     * Holds the QueueConnection instance to use for the server connect.
40
     *
41
     * @var \AppserverIo\Messaging\QueueConnection
42
     */
43
    protected $connection = null;
44
45
    /**
46
     * Holds the unique session id.
47
     *
48
     * @var string
49
     */
50
    protected $id = null;
51
52
    /**
53
     * Initializes the session with the QueueConnection instance
54
     * to use for the server connection.
55
     *
56
     * @param \AppserverIo\Messaging\QueueConnection $connection Holds the QueueConnection instance to use
57
     */
58
    public function __construct(QueueConnection $connection)
59
    {
60
        // initialize the internal connection
61
        $this->connection = $connection;
62
        // generate and return the unique session id
63
        return $this->id = md5(uniqid(rand(), true));
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
64
    }
65
66
    /**
67
     * Sends the passed Message instance to the server,
68
     * using the QueueConnection instance.
69
     *
70
     * @param \AppserverIo\Psr\Pms\MessageInterface $message          The message to send
71
     * @param boolean                               $validateResponse If this flag is true, the QueueConnection waits for the MessageQueue response and validates it
72
     *
73
     * @return \AppserverIo\Messaging\QueueResponse The response of the MessageQueue, or null
74
     */
75
    public function send(MessageInterface $message, $validateResponse)
76
    {
77
        return $this->connection->send($message, $validateResponse);
78
    }
79
80
    /**
81
     * Creates and returns a new QueueSender instance for sending
82
     * the Message to the server.
83
     *
84
     * @param \AppserverIo\Psr\Pms\QueueInterface $queue the Queue instance to use for sending the message
85
     *
86
     * @return \AppserverIo\Messaging\QueueSender The initialized QueueSender instance
87
     */
88
    public function createSender(QueueInterface $queue)
89
    {
90
        return new QueueSender($this, $queue);
91
    }
92
93
    /**
94
     * Returns the session id.
95
     *
96
     * @return string The unique id
97
     */
98
    public function getId()
99
    {
100
        return $this->id;
101
    }
102
}
103