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.

AudienceVerifierTest::testArrayAudience()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace Emarref\Jwt\Verification;
4
5
use Emarref\Jwt\Claim;
6
7
class AudienceVerifierTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token\Payload
11
     */
12
    private $payload;
13
14
    /**
15
     * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token
16
     */
17
    private $token;
18
19
    public function setUp()
20
    {
21
        $this->payload = $this->getMockBuilder('Emarref\Jwt\Token\Payload')->getMock();
22
23
        $this->token = $this->getMockBuilder('Emarref\Jwt\Token')->getMock();
24
    }
25
26
    /**
27
     * @expectedException \InvalidArgumentException
28
     * @expectedExceptionMessage Cannot verify invalid audience value.
29
     */
30
    public function testInvalidAudience()
31
    {
32
        new AudienceVerifier(new \stdClass());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, 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...
33
    }
34
35
    public function testNoAudienceInToken()
36
    {
37
        $this->token->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
38
            ->method('getPayload')
39
            ->will($this->returnValue($this->payload));
40
41
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
42
            ->method('findClaimByName')
43
            ->with(Claim\Audience::NAME)
44
            ->will($this->returnValue(null));
45
46
        $verifier = new AudienceVerifier();
47
        $verifier->verify($this->token);
48
    }
49
50
    /**
51
     * @expectedException \Emarref\Jwt\Exception\InvalidAudienceException
52
     * @expectedExceptionMessage Audience is invalid.
53
     */
54
    public function testInvalidAudienceInToken()
55
    {
56
        $expectedAudience = 'urn://myaudience';
57
58
        $audienceClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Audience')->getMock();
59
60
        $audienceClaim->expects($this->once())
61
            ->method('getValue')
62
            ->will($this->returnValue($expectedAudience));
63
64
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
65
            ->method('findClaimByName')
66
            ->with(Claim\Audience::NAME)
67
            ->will($this->returnValue($audienceClaim));
68
69
        $this->token->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
70
            ->method('getPayload')
71
            ->will($this->returnValue($this->payload));
72
73
        $verifier = new AudienceVerifier('foobar');
74
        $verifier->verify($this->token);
75
    }
76
77
    public function testArrayAudience()
78
    {
79
        $audienceClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Audience')->getMock();
80
81
        $audienceClaim->expects($this->once())
82
                      ->method('getValue')
83
                      ->will($this->returnValue(['urn://audienceone', 'urn://audiencetwo']));
84
85
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
86
                      ->method('findClaimByName')
87
                      ->with(Claim\Audience::NAME)
88
                      ->will($this->returnValue($audienceClaim));
89
90
        $this->token->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
91
                    ->method('getPayload')
92
                    ->will($this->returnValue($this->payload));
93
94
        $verifier = new AudienceVerifier('urn://audienceone');
95
        $verifier->verify($this->token);
96
    }
97
98
    public function testStringAudience()
99
    {
100
        $audienceClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Audience')->getMock();
101
102
        $audienceClaim->expects($this->once())
103
                      ->method('getValue')
104
                      ->will($this->returnValue('urn://audienceone'));
105
106
        $this->payload->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token\Payload.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
107
                      ->method('findClaimByName')
108
                      ->with(Claim\Audience::NAME)
109
                      ->will($this->returnValue($audienceClaim));
110
111
        $this->token->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Emarref\Jwt\Token.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
112
                    ->method('getPayload')
113
                    ->will($this->returnValue($this->payload));
114
115
        $verifier = new AudienceVerifier('urn://audienceone');
116
        $verifier->verify($this->token);
117
    }
118
}
119