Stomp   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A __destruct() 0 4 1
A add() 0 6 2
A del() 0 6 2
A get() 0 13 3
1
<?php
2
3
namespace Aimeos\MW\MQueue\Queue;
4
5
6
class Stomp implements Iface
7
{
8
	private $client;
9
	private $queue;
10
11
12
	/**
13
	 * Initializes the message queue class
14
	 *
15
	 * @param \Stomp $client Stomp object
16
	 * @param string $queue Message queue name
17
	 * @throws \Aimeos\MW\MQueue\Exception
18
	 */
19
	public function __construct( \Stomp $client, $queue )
20
	{
21
		if( $client->subscribe( $queue ) === false ) {
22
			throw new \Aimeos\MW\MQueue\Exception( $client->error() );
23
		}
24
25
		$this->client = $client;
26
		$this->queue = $queue;
27
	}
28
29
30
	/**
31
	 * Unsubscribes from the queue on cleanup
32
	 */
33
	public function __destruct()
34
	{
35
		$this->client->unsubscribe( $this->queue );
36
	}
37
38
39
	/**
40
	 * Adds a new message to the message queue
41
	 *
42
	 * @param string $msg Message, e.g. JSON encoded data
43
	 * @throws \Aimeos\MW\MQueue\Exception
44
	 */
45
	public function add( $msg )
46
	{
47
		if( $this->client->send( $this->queue, $msg ) === false ) {
48
			throw new \Aimeos\MW\MQueue\Exception( $this->client->error() );
49
		}
50
	}
51
52
53
	/**
54
	 * Removes the message from the queue
55
	 *
56
	 * @param \Aimeos\MW\MQueue\Message\Iface $msg Message object
57
	 * @throws \Aimeos\MW\MQueue\Exception
58
	 */
59
	public function del( \Aimeos\MW\MQueue\Message\Iface $msg )
60
	{
61
		if( $this->client->ack( $msg->getObject() ) === false ) {
62
			throw new \Aimeos\MW\MQueue\Exception( $this->client->error() );
63
		}
64
	}
65
66
67
	/**
68
	 * Returns the next message from the queue
69
	 *
70
	 * @return \Aimeos\MW\MQueue\Message\Iface|null Message object or null if none is available
71
	 * @throws \Aimeos\MW\MQueue\Exception
72
	 */
73
	public function get()
74
	{
75
		try
76
		{
77
			if( $this->client->hasFrame() ) {
78
				return new \Aimeos\MW\MQueue\Message\Stomp( $this->client->readFrame() );
79
			}
80
		}
81
		catch( \StompException $e )
0 ignored issues
show
Bug introduced by
The class StompException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
82
		{
83
			throw new \Aimeos\MW\MQueue\Exception( $e->getMessage() );
84
		}
85
	}
86
}