Stomp   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 66
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 66
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C getQueue() 0 36 8
A connect() 0 8 2
1
<?php
2
3
namespace Aimeos\MW\MQueue;
4
5
6
class Stomp extends Base implements Iface
7
{
8
	private $queues = array();
9
10
11
	/**
12
	 * Returns the queue for the given name
13
	 *
14
	 * @param string $name Queue name
15
	 * @return \Aimeos\MW\MQueue\Queue\Iface Message queue
16
	 */
17
	public function getQueue( $name )
18
	{
19
		if( !isset( $this->queues[$name] ) )
20
		{
21
			$uri = $this->getConfig( 'uri', 'tcp://localhost:61613' );
22
			$user = $this->getConfig( 'username', null );
23
			$pass = $this->getConfig( 'password', null );
24
25
			if( is_array( $uri ) )
26
			{
27
				foreach( $uri as $idx => $entry )
28
				{
29
					$iuser = ( is_array( $user) ? $user[$idx] : $user );
30
					$ipass = ( is_array( $pass) ? $pass[$idx] : $pass );
31
32
					$result = $this->connect( $entry, $iuser, $ipass );
33
34
					if( $result instanceof \Stomp ) {
0 ignored issues
show
Bug introduced by
The class Stomp does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
35
						break;
36
					}
37
				}
38
			}
39
			else
40
			{
41
				$result = $this->connect( $uri, $user, $pass );
42
			}
43
44
			if( $result instanceof \StompException ) {
0 ignored issues
show
Bug introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The class StompException does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
45
				throw new \Aimeos\MW\MQueue\Exception( $result->getMessage() );
46
			}
47
48
			$this->queues[$name] = new \Aimeos\MW\MQueue\Queue\Stomp( $result, $name );
49
		}
50
51
		return $this->queues[$name];
52
	}
53
54
55
	/**
56
	 * Opens a connection to the message queue server
57
	 *
58
	 * @param string $uri Connection URI
59
	 * @param string $user User name for authentication
60
	 * @param string $pass Password for authentication
61
	 * @return \Stomp|\StompException
62
	 */
63
	protected function connect( $uri, $user, $pass )
64
	{
65
		try {
66
			return new \Stomp( $uri, $user, $pass );
67
		} 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...
68
			return $e;
69
		}
70
	}
71
}