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.

TimedGeocoderTest::testGeocodeThrowsException()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Tests;
14
15
use Geocoder\Model\AddressCollection;
16
use Geocoder\Provider\Provider;
17
use Geocoder\TimedGeocoder;
18
use PHPUnit\Framework\TestCase;
19
use Symfony\Component\Stopwatch\Stopwatch;
20
21
class TimedGeocoderTest extends TestCase
22
{
23
    /**
24
     * @var Stopwatch
25
     */
26
    private $stopwatch;
27
28
    /**
29
     * @var Provider|\PHPUnit_Framework_MockObject_MockObject
30
     */
31
    private $delegate;
32
33
    /**
34
     * @var TimedGeocoder
35
     */
36
    private $geocoder;
37
38
    protected function setUp()
39
    {
40
        $this->stopwatch = new Stopwatch();
41
        $this->delegate = $this->getMockBuilder(Provider::class)->getMock();
42
        $this->geocoder = new TimedGeocoder($this->delegate, $this->stopwatch);
43
    }
44
45
    public function testGeocode()
46
    {
47
        $this->delegate->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Geocoder\Provider\Provider.

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...
48
             ->method('geocodeQuery')
49
             ->will($this->returnValue(new AddressCollection([])));
50
51
        $this->geocoder->geocode('foo');
52
53
        $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__'));
54
    }
55
56
    public function testGeocodeThrowsException()
57
    {
58
        $this->delegate->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Geocoder\Provider\Provider.

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...
59
             ->method('geocodeQuery')
60
             ->will($this->throwException($exception = new \Exception()));
61
62
        try {
63
            $this->geocoder->geocode('foo');
64
            $this->fail('Geocoder::geocode should throw an exception');
65
        } catch (\Exception $e) {
66
            $this->assertSame($exception, $e);
67
        }
68
69
        $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__'));
70
    }
71
72
    public function testReverse()
73
    {
74
        $this->delegate->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Geocoder\Provider\Provider.

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...
75
             ->method('reverseQuery')
76
             ->will($this->returnValue(new AddressCollection([])));
77
78
        $this->geocoder->reverse(0, 0);
79
80
        $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__'));
81
    }
82
83
    public function testReverseThrowsException()
84
    {
85
        $this->delegate->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Geocoder\Provider\Provider.

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('reverseQuery')
87
             ->will($this->throwException($exception = new \Exception()));
88
89
        try {
90
            $this->geocoder->reverse(0, 0);
91
            $this->fail('Geocoder::reverse should throw an exception');
92
        } catch (\Exception $e) {
93
            $this->assertSame($exception, $e);
94
        }
95
96
        $this->assertCount(1, $this->stopwatch->getSectionEvents('__root__'));
97
    }
98
}
99