StompTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 58.33 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 7
c 2
b 0
f 2
lcom 0
cbo 1
dl 35
loc 60
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 2
A testProcess() 19 19 2
A testGetQueueSingleConnection() 0 4 1
A testGetQueueMultiConnection() 0 4 1
A testGetQueue() 16 16 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Aimeos\MW\MQueue;
4
5
6
class StompTest extends \PHPUnit_Framework_TestCase
7
{
8
	protected function setUp()
9
	{
10
		if( class_exists( '\Stomp' ) === false ) {
11
			$this->markTestSkipped( 'Please install the "stomp" PHP extension first' );
12
		}
13
	}
14
15
16 View Code Duplication
	public function testProcess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
	{
18
		try
19
		{
20
			$config = array( 'username' => 'guest', 'password' => 'guest' );
21
			$mqueue = new \Aimeos\MW\MQueue\Stomp( $config );
22
			$queue = $mqueue->getQueue( 'aimeos_unittest' );
23
		}
24
		catch( \Aimeos\MW\MQueue\Exception $e )
0 ignored issues
show
Bug introduced by
The class Aimeos\MW\MQueue\Exception 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...
25
		{
26
			$this->markTestSkipped( 'No Stomp compliant server available at "localhost"' );
27
		}
28
29
		$queue->add( 'testmsg' );
0 ignored issues
show
Bug introduced by
The variable $queue 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...
30
		$msg = $queue->get();
31
		$queue->del( $msg );
32
33
		$this->assertNull( $queue->get() );
34
	}
35
36
37
	public function testGetQueueSingleConnection()
38
	{
39
		$object = new \Aimeos\MW\MQueue\Stomp( array( 'host' => 'tcp://127.0.0.1:61616' ) );
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
	}
41
42
43
	public function testGetQueueMultiConnection()
44
	{
45
		$object = new \Aimeos\MW\MQueue\Stomp( array( 'host' => array( 'tcp://127.0.0.1:61616', 'tcp://127.0.0.1:61617' ) ) );
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46
	}
47
48
49 View Code Duplication
	public function testGetQueue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
	{
51
		$client = $this->getMockBuilder( '\Stomp' )
52
			->disableOriginalConstructor()
53
			->getMock();
54
55
		$object = $this->getMockBuilder( '\Aimeos\MW\MQueue\Stomp' )
56
			->setMethods( array( 'connect' ) )
57
			->disableOriginalConstructor()
58
			->getMock();
59
60
		$object->expects( $this->once() )->method( 'connect' )
61
			->will( $this->returnValue( $client ) );
62
63
		$this->assertInstanceOf( '\Aimeos\MW\MQueue\Queue\Iface', $object->getQueue( 'test' ) );
64
	}
65
}
66