GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RelationPropertyMetadataTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 53.23 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 33
loc 62
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test() 0 9 1
A testWithExclusion() 0 14 1
A testWithEmbeddedRelation() 17 17 1
A testWithLinkRelation() 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 Hateoas\Tests\Serializer\Metadata;
4
5
use Hateoas\Configuration\Embedded;
6
use Hateoas\Configuration\Exclusion;
7
use Hateoas\Configuration\Relation;
8
use Hateoas\Configuration\Route;
9
use Hateoas\Serializer\Metadata\RelationPropertyMetadata;
10
use Hateoas\Tests\TestCase;
11
12
class RelationPropertyMetadataTest extends TestCase
13
{
14
    public function test()
15
    {
16
        $propertyMetadata = new RelationPropertyMetadata();
17
18
        $this->assertNull($propertyMetadata->groups);
19
        $this->assertNull($propertyMetadata->sinceVersion);
20
        $this->assertNull($propertyMetadata->untilVersion);
21
        $this->assertNull($propertyMetadata->maxDepth);
22
    }
23
24
    public function testWithExclusion()
25
    {
26
        $propertyMetadata = new RelationPropertyMetadata(new Exclusion(
27
            array('foo', 'bar'),
28
            1.1,
29
            2.2,
30
            42
31
        ));
32
33
        $this->assertSame(['foo', 'bar'], $propertyMetadata->groups);
34
        $this->assertSame(1.1, $propertyMetadata->sinceVersion);
35
        $this->assertSame(2.2, $propertyMetadata->untilVersion);
36
        $this->assertSame(42, $propertyMetadata->maxDepth);
37
    }
38
39 View Code Duplication
    public function testWithEmbeddedRelation()
0 ignored issues
show
Duplication introduced by fsevestre
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...
40
    {
41
        $propertyMetadata = new RelationPropertyMetadata(null, new Relation(
42
            'foo',
43
            null,
44
            new Embedded('bar', array('name' => 'John'))
0 ignored issues
show
Documentation introduced by fsevestre
array('name' => 'John') is of type array<string,string,{"name":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
        ));
46
47
        $this->assertSame('foo', $propertyMetadata->name);
48
        $this->assertSame('Hateoas\Configuration\Relation', $propertyMetadata->class);
49
        $this->assertSame(
50
            [
51
                'name' => 'Hateoas\Model\Embedded',
52
                'params' => [],
53
            ], $propertyMetadata->type
54
        );
55
    }
56
57 View Code Duplication
    public function testWithLinkRelation()
0 ignored issues
show
Duplication introduced by fsevestre
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...
58
    {
59
        $propertyMetadata = new RelationPropertyMetadata(null, new Relation(
60
            'foo',
61
            new Route('/route', array('foo' => 'bar'))
62
        ));
63
64
        $this->assertSame('foo', $propertyMetadata->name);
65
        $this->assertSame('Hateoas\Configuration\Relation', $propertyMetadata->class);
66
        $this->assertSame(
67
            [
68
                'name' => 'Hateoas\Model\Link',
69
                'params' => [],
70
            ], $propertyMetadata->type
71
        );
72
    }
73
}
74