Completed
Push — issue#666 ( 2654e9...77cc5b )
by Guilherme
03:52
created

testGetRemoteClaimsFromAuthorization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\RemoteClaimsBundle\Tests\Model;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use LoginCidadao\CoreBundle\Entity\Authorization;
15
use LoginCidadao\OAuthBundle\Model\ClientInterface;
16
use LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimAuthorizationRepository;
17
use LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimRepository;
18
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimAuthorizationInterface;
19
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimManager;
20
use LoginCidadao\CoreBundle\Model\PersonInterface;
21
use LoginCidadao\RemoteClaimsBundle\Model\TagUri;
22
23
class RemoteClaimManagerTest extends \PHPUnit_Framework_TestCase
24
{
25
    public function testEnforceNewAuthorization()
26
    {
27
        $authorization = $this->getRemoteClaimAuthorization();
28
29
        $em = $this->getEntityManager();
30
        $em->expects($this->once())->method('persist')->with($authorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

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...
31
32
        $repo = $this->getRepo();
33
        $repo->expects($this->once())->method('findAuthorization')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
34
35
        $manager = new RemoteClaimManager($em, $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 29 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 32 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
36
        $this->assertSame($authorization, $manager->enforceAuthorization($authorization));
0 ignored issues
show
Bug introduced by
It seems like $authorization defined by $this->getRemoteClaimAuthorization() on line 27 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...:enforceAuthorization() does only seem to accept object<LoginCidadao\Remo...AuthorizationInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
37
    }
38
39
    public function testEnforceExistingAuthorization()
40
    {
41
        $authorization = $this->getRemoteClaimAuthorization();
42
        $existingAuthorization = $this->getRemoteClaimAuthorization();
43
44
        $em = $this->getEntityManager();
45
        $em->expects($this->never())->method('persist');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

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...
46
47
        $repo = $this->getRepo();
48
        $repo->expects($this->once())->method('findAuthorization')->willReturn($existingAuthorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
49
50
        $manager = new RemoteClaimManager($em, $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 44 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 47 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
51
        $this->assertSame($existingAuthorization, $manager->enforceAuthorization($authorization));
0 ignored issues
show
Bug introduced by
It seems like $authorization defined by $this->getRemoteClaimAuthorization() on line 41 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...:enforceAuthorization() does only seem to accept object<LoginCidadao\Remo...AuthorizationInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
    }
53
54
    public function testIsAuthorizedClaimNameString()
55
    {
56
        $claimName = 'tag:example.com,2017:my_claim';
57
        $person = $this->getPerson();
58
        $client = $this->getClient();
59
        $authorization = $this->getRemoteClaimAuthorization();
60
61
        $repo = $this->getRepo();
62
        $repo->expects($this->once())->method('findAuthorization')->willReturn($authorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
63
64
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 61 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
65
66
        $this->assertTrue($manager->isAuthorized($claimName, $person, $client));
0 ignored issues
show
Bug introduced by
It seems like $person defined by $this->getPerson() on line 57 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\Core...\Model\PersonInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $client defined by $this->getClient() on line 58 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\OAut...\Model\ClientInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67
    }
68
69
    public function testIsAuthorizedTagUri()
70
    {
71
        $claimName = new TagUri();
72
        $person = $this->getPerson();
73
        $client = $this->getClient();
74
        $authorization = $this->getRemoteClaimAuthorization();
75
76
        $repo = $this->getRepo();
77
        $repo->expects($this->once())->method('findAuthorization')->willReturn($authorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
78
79
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 76 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
80
81
        $this->assertTrue($manager->isAuthorized($claimName, $person, $client));
0 ignored issues
show
Bug introduced by
It seems like $person defined by $this->getPerson() on line 72 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\Core...\Model\PersonInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $client defined by $this->getClient() on line 73 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\OAut...\Model\ClientInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
82
    }
83
84
    public function testIsNotAuthorizedTagUri()
85
    {
86
        $claimName = new TagUri();
87
        $person = $this->getPerson();
88
        $client = $this->getClient();
89
90
        $repo = $this->getRepo();
91
        $repo->expects($this->once())->method('findAuthorization')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
92
93
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 90 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94
95
        $this->assertFalse($manager->isAuthorized($claimName, $person, $client));
0 ignored issues
show
Bug introduced by
It seems like $person defined by $this->getPerson() on line 87 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\Core...\Model\PersonInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $client defined by $this->getClient() on line 88 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\OAut...\Model\ClientInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
96
    }
97
98
    public function testRevokeAllAuthorizations()
99
    {
100
        $remoteClaimAuthorizations = [
101
            $this->getRemoteClaimAuthorization(),
102
            $this->getRemoteClaimAuthorization(),
103
        ];
104
105
        $authorization = $this->getAuthorization();
106
        $authorization->expects($this->once())->method('getPerson')->willReturn($this->getPerson());
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\CoreBundle\Entity\Authorization.

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
        $authorization->expects($this->once())->method('getClient')->willReturn($this->getClient());
108
109
        $em = $this->getEntityManager();
110
        $em->expects($this->exactly(count($remoteClaimAuthorizations)))->method('remove')
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

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...
111
            ->with($this->isInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimAuthorizationInterface'));
112
113
        $repo = $this->getRepo();
114
        $repo->expects($this->once())->method('findAllByClientAndPerson')->willReturn($remoteClaimAuthorizations);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
115
116
        $manager = new RemoteClaimManager($em, $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 109 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 113 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
117
        $manager->revokeAllAuthorizations($authorization);
0 ignored issues
show
Bug introduced by
It seems like $authorization defined by $this->getAuthorization() on line 105 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...vokeAllAuthorizations() does only seem to accept object<LoginCidadao\Core...e\Entity\Authorization>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
118
    }
119
120
    public function testFilterRemoteClaimsString()
121
    {
122
        $scopes = 'scope1 scope2 tag:example.com,2017:my_claim scope3';
123
        $manager = new RemoteClaimManager($this->getEntityManager(), $this->getRepo(), $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRepo() targeting LoginCidadao\RemoteClaim...mManagerTest::getRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
124
        $result = $manager->filterRemoteClaims($scopes);
125
126
        $this->assertEquals('scope1 scope2 scope3', $result);
127
    }
128
129
    public function testFilterRemoteClaimsArray()
130
    {
131
        $scopes = ['scope1', 'scope2', 'tag:example.com,2017:my_claim', 'scope3'];
132
        $manager = new RemoteClaimManager($this->getEntityManager(), $this->getRepo(), $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRepo() targeting LoginCidadao\RemoteClaim...mManagerTest::getRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
133
        $result = $manager->filterRemoteClaims($scopes);
134
135
        $this->assertEquals(['scope1', 'scope2', 'scope3'], $result);
136
    }
137
138
    public function testFilterRemoteClaimsNoAction()
139
    {
140
        $scopes = 'scope1 scope2 scope3';
141
        $manager = new RemoteClaimManager($this->getEntityManager(), $this->getRepo(), $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRepo() targeting LoginCidadao\RemoteClaim...mManagerTest::getRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
142
        $result = $manager->filterRemoteClaims($scopes);
143
144
        $this->assertEquals('scope1 scope2 scope3', $result);
145
    }
146
147
    public function testFilterRemoteClaimsEmptyString()
148
    {
149
        $scopes = '';
150
        $manager = new RemoteClaimManager($this->getEntityManager(), $this->getRepo(), $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRepo() targeting LoginCidadao\RemoteClaim...mManagerTest::getRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
151
        $result = $manager->filterRemoteClaims($scopes);
152
153
        $this->assertEquals('', $result);
154
    }
155
156
    public function testFilterRemoteClaimsEmptyArray()
157
    {
158
        $scopes = [];
159
        $manager = new RemoteClaimManager($this->getEntityManager(), $this->getRepo(), $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRepo() targeting LoginCidadao\RemoteClaim...mManagerTest::getRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
160
        $result = $manager->filterRemoteClaims($scopes);
161
162
        $this->assertEquals([], $result);
163
    }
164
165
    public function testGetRemoteClaimsFromAuthorization()
166
    {
167
        $client = $this->getClient();
168
        $person = $this->getPerson();
169
170
        /** @var \PHPUnit_Framework_MockObject_MockObject|Authorization $authorization */
171
        $authorization = $this->getMock('LoginCidadao\CoreBundle\Entity\Authorization');
172
        $authorization->expects($this->once())->method('getClient')->willReturn($client);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\CoreBundle\Entity\Authorization.

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...
173
        $authorization->expects($this->once())->method('getPerson')->willReturn($person);
174
175
        $repo = $this->getRemoteClaimRepo();
176
        $repo->expects($this->once())->method('findByClientAndPerson')
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...y\RemoteClaimRepository.

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...
177
            ->with($client, $person);
178
179
        $manager = new RemoteClaimManager($this->getEntityManager(), $this->getRepo(), $repo);
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $this->getRepo() targeting LoginCidadao\RemoteClaim...mManagerTest::getRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRemoteClaimRepo() on line 175 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
180
        $manager->getRemoteClaimsFromAuthorization($authorization);
181
    }
182
183
    public function testGetRemoteClaimsAuthorizationsFromAuthorization()
184
    {
185
        $client = $this->getClient();
186
        $person = $this->getPerson();
187
188
        /** @var \PHPUnit_Framework_MockObject_MockObject|Authorization $authorization */
189
        $authorization = $this->getMock('LoginCidadao\CoreBundle\Entity\Authorization');
190
        $authorization->expects($this->once())->method('getClient')->willReturn($client);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\CoreBundle\Entity\Authorization.

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...
191
        $authorization->expects($this->once())->method('getPerson')->willReturn($person);
192
193
        $repo = $this->getRepo();
194
        $repo->expects($this->once())->method('findAllByClientAndPerson')
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
195
            ->with($client, $person);
196
197
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo, $this->getRemoteClaimRepo());
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 193 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $this->getRemoteClaimRepo() targeting LoginCidadao\RemoteClaim...t::getRemoteClaimRepo() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...\RemoteClaimRepository>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
198
        $manager->getRemoteClaimsAuthorizationsFromAuthorization($authorization);
199
    }
200
201
    /**
202
     * @return \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface
203
     */
204
    private function getEntityManager()
205
    {
206
        return $this->getMock('Doctrine\ORM\EntityManagerInterface');
207
    }
208
209
    /**
210
     * @return \PHPUnit_Framework_MockObject_MockObject|RemoteClaimAuthorizationRepository
211
     */
212
    private function getRepo()
213
    {
214
        return $this->getMockBuilder('LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimAuthorizationRepository')
215
            ->disableOriginalConstructor()->getMock();
216
    }
217
218
    /**
219
     * @return \PHPUnit_Framework_MockObject_MockObject|RemoteClaimRepository
220
     */
221
    private function getRemoteClaimRepo()
222
    {
223
        return $this->getMockBuilder('LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimRepository')
224
            ->disableOriginalConstructor()->getMock();
225
    }
226
227
    /**
228
     * @return \PHPUnit_Framework_MockObject_MockObject|RemoteClaimAuthorizationInterface
229
     */
230
    private function getRemoteClaimAuthorization()
231
    {
232
        return $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimAuthorizationInterface');
233
    }
234
235
    /**
236
     * @return \PHPUnit_Framework_MockObject_MockObject|PersonInterface
237
     */
238
    private function getPerson()
239
    {
240
        return $this->getMock('LoginCidadao\CoreBundle\Model\PersonInterface');
241
    }
242
243
    /**
244
     * @return \PHPUnit_Framework_MockObject_MockObject|ClientInterface
245
     */
246
    private function getClient()
247
    {
248
        return $this->getMock('LoginCidadao\OAuthBundle\Model\ClientInterface');
249
    }
250
251
    /**
252
     * @return \PHPUnit_Framework_MockObject_MockObject|Authorization
253
     */
254
    private function getAuthorization()
255
    {
256
        return $this->getMock('LoginCidadao\CoreBundle\Entity\Authorization');
257
    }
258
}
259