AbstractSerializerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 18.75 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 9
dl 6
loc 32
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 6 19 1
A assertJsonEquals() 0 4 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
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Serializer\Tests;
13
14
use JMS\Serializer\EventDispatcher\EventDispatcher;
15
use JMS\Serializer\Handler\HandlerRegistryInterface;
16
use JMS\Serializer\SerializerBuilder;
17
use JMS\Serializer\SerializerInterface;
18
use Xabbuh\XApi\Serializer\Event\ActorEventSubscriber;
19
use Xabbuh\XApi\Serializer\Event\DocumentDataWrapper;
20
use Xabbuh\XApi\Serializer\Event\ObjectEventSubscriber;
21
use Xabbuh\XApi\Serializer\Event\SetSerializedTypeEventSubscriber;
22
use Xabbuh\XApi\Serializer\Handler\DocumentDataUnwrapper;
23
24
/**
25
 * @author Christian Flothmann <[email protected]>
26
 */
27
abstract class AbstractSerializerTest extends \PHPUnit_Framework_TestCase
28
{
29
    /**
30
     * @var SerializerInterface
31
     */
32
    protected $serializer;
33
34
    protected function setUp()
35
    {
36
        $builder = SerializerBuilder::create();
37
        $builder->addMetadataDir(__DIR__.'/../metadata', 'Xabbuh\XApi\Model');
38
        $builder->configureListeners(
39 View Code Duplication
            function (EventDispatcher $dispatcher) {
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...
40
                $dispatcher->addSubscriber(new ActorEventSubscriber());
41
                $dispatcher->addSubscriber(new DocumentDataWrapper());
42
                $dispatcher->addSubscriber(new ObjectEventSubscriber());
43
                $dispatcher->addSubscriber(new SetSerializedTypeEventSubscriber());
44
            }
45
        );
46
        $builder->configureHandlers(
47
            function (HandlerRegistryInterface $registry) {
48
                $registry->registerSubscribingHandler(new DocumentDataUnwrapper());
49
            }
50
        );
51
        $this->serializer = $builder->build();
52
    }
53
54
    protected function assertJsonEquals($expected, $actual)
55
    {
56
        $this->assertEquals(json_decode($expected), json_decode($actual));
57
    }
58
}
59