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.

LinkExpressionFunctionTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 62
c 3
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testEvaluate() 0 14 1
A testCompile() 0 18 1
A mockHelper() 0 17 1
1
<?php
2
3
namespace Hateoas\Tests\Expression;
4
5
use Hateoas\Expression\ExpressionEvaluator;
6
use Hateoas\Expression\LinkExpressionFunction;
7
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
8
9
class LinkExpressionFunctionTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testEvaluate()
12
    {
13
        $object = new \StdClass();
14
15
        $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
16
17
        $expressionEvaluator = new ExpressionEvaluator(new ExpressionLanguage());
18
        $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
19
20
        $this->assertEquals(
21
            '/foo',
22
            $expressionEvaluator->evaluate('expr(link(object, "self", false))', $object)
23
        );
24
    }
25
26
    public function testCompile()
27
    {
28
        $object = new \StdClass();
29
30
        $linkHelperMock = $this->mockHelper('/foo', $object, 'self', false);
31
32
        $expressionLanguage = new ExpressionLanguage();
33
        $expressionEvaluator = new ExpressionEvaluator($expressionLanguage);
34
        $expressionEvaluator->registerFunction(new LinkExpressionFunction($linkHelperMock));
35
36
        $compiledExpression = $expressionLanguage->compile('link(object, "self", false)', array('object', 'link_helper'));
37
38
        // setup variables for expression eval
39
        $object = $object;
0 ignored issues
show
Bug introduced by
Why assign $object to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
40
        $link_helper = $linkHelperMock;
0 ignored issues
show
Unused Code introduced by
$link_helper 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...
41
42
        $this->assertEquals('/foo', eval(sprintf('return %s;', $compiledExpression)));
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
43
    }
44
45
    /**
46
     * @param string $result
47
     * @param \stdClass $expectedObject
48
     * @param string $expectedRel
49
     * @param boolean $expectedAbsolute
50
     *
51
     * @return \Hateoas\Helper\LinkHelper
52
     */
53
    private function mockHelper($result, $expectedObject, $expectedRel, $expectedAbsolute)
0 ignored issues
show
Unused Code introduced by
The parameter $result is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        $linkHelperMock = $this
56
            ->getMockBuilder('Hateoas\Helper\LinkHelper')
57
            ->disableOriginalConstructor()
58
            ->getMock()
59
        ;
60
61
        $linkHelperMock
62
            ->expects($this->once())
63
            ->method('getLinkHref')
64
            ->will($this->returnValue('/foo'))
65
            ->with($expectedObject, $expectedRel, $expectedAbsolute)
66
        ;
67
68
        return $linkHelperMock;
69
    }
70
}
71