PushTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 10
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testForwardEventToPushServer() 10 32 3

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 Eole\Sandstone\Tests\Integration;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Eole\Sandstone\Push\PushServerInterface;
7
use Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent;
8
9
class PushTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testForwardEventToPushServer()
12
    {
13
        $pushServerMock = $this->getMockForAbstractClass(PushServerInterface::class);
14
15
        $app = new App\AppRestApi([
16
            'debug' => true,
17
            'sandstone.push' => function () use ($pushServerMock) {
18
                return $pushServerMock;
19
            },
20
        ]);
21
22
        $app->boot();
23
24
        $pushServerMock
25
            ->expects($this->once())
26
            ->method('send')
27 View Code Duplication
            ->with($this->callback(function ($message) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
28
                $decodedMessage = unserialize($message);
29
                $serializedEvent = '{"propagation_stopped":false,"id":42,"title":"Unicorns spotted in Alaska","url":"http:\/\/unicorn.com\/articles\/unicorns-spotted-alaska"}';
30
31
                return
32
                    ArticleCreatedEvent::ARTICLE_CREATED_EVENT === $decodedMessage['name'] &&
33
                    ArticleCreatedEvent::class === $decodedMessage['class'] &&
34
                    $serializedEvent === $decodedMessage['event']
35
                ;
36
            }))
37
        ;
38
39
        $result = $app->handle(Request::create('/api/articles', Request::METHOD_POST));
40
41
        $this->assertEquals(42, $result->getContent());
42
    }
43
}
44