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.

HateoasTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 52.17 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 6
dl 24
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 24 24 5
A testGetLinkHrefUrlWithAbsoluteTrue() 0 4 1
A testGetLinkHrefUrlWithUnknownRelShouldReturnNull() 0 5 1
A testGetLinkHrefUrl() 0 5 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;
4
5
use Hateoas\HateoasBuilder;
6
use Hateoas\UrlGenerator\CallableUrlGenerator;
7
use Hateoas\Tests\Fixtures\Will;
8
9
class HateoasTest extends \PHPUnit_Framework_TestCase
10
{
11
    private $hateoas;
12
13 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by William DURAND
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...
14
    {
15
        $this->hateoas = HateoasBuilder::create()
16
            ->setUrlGenerator(null, new CallableUrlGenerator(function ($name, $parameters, $absolute) {
17
                if ($name === 'user_get') {
18
                    return sprintf(
19
                        '%s%s',
20
                        $absolute ? 'http://example.com' : '',
21
                        strtr('/users/id', $parameters)
22
                    );
23
                }
24
25
                if ($name === 'post_get') {
26
                    return sprintf(
27
                        '%s%s',
28
                        $absolute ? 'http://example.com' : '',
29
                        strtr('/posts/id', $parameters)
30
                    );
31
                }
32
33
                throw new \RuntimeException('Cannot generate URL');
34
            }))
35
            ->build();
36
    }
37
38
    public function testGetLinkHrefUrlWithUnknownRelShouldReturnNull()
39
    {
40
        $this->assertNull($this->hateoas->getLinkHelper()->getLinkHref(new Will(123), 'unknown-rel'));
41
        $this->assertNull($this->hateoas->getLinkHelper()->getLinkHref(new Will(123), 'unknown-rel', true));
42
    }
43
44
    public function testGetLinkHrefUrl()
45
    {
46
        $this->assertEquals('/users/123', $this->hateoas->getLinkHelper()->getLinkHref(new Will(123), 'self'));
47
        $this->assertEquals('/users/123', $this->hateoas->getLinkHelper()->getLinkHref(new Will(123), 'self', false));
48
    }
49
50
    public function testGetLinkHrefUrlWithAbsoluteTrue()
51
    {
52
        $this->assertEquals('http://example.com/users/123', $this->hateoas->getLinkHelper()->getLinkHref(new Will(123), 'self', true));
53
    }
54
}
55