Completed
Pull Request — master (#5)
by Jean-Baptiste
01:43
created

Guzzle5Mock::getMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace CanalTP\AbstractGuzzle\Mock;
4
5
use CanalTP\AbstractGuzzle\GuzzleFactory;
6
use GuzzleHttp\Subscriber\Mock;
7
8
class Guzzle5Mock
9
{
10
    /**
11
     * @param array $responseCollection
12
     * @return \CanalTP\AbstractGuzzle\Guzzle
13
     */
14
    public function getMock(array $responseCollection)
15
    {
16
        $client = GuzzleFactory::createGuzzle('');
17
        $mock = new Mock($responseCollection);
18
        $client->getEmitter()->attach($mock);
0 ignored issues
show
Bug introduced by
The method getEmitter does only exist in CanalTP\AbstractGuzzle\Version\Guzzle5, but not in CanalTP\AbstractGuzzle\V...tGuzzle\Version\Guzzle6.

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...
19
20
        return $client;
21
    }
22
}
23