InputInterfaceTrait::shouldGetInputFirstArgument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace PhpGitHooks\Module\Shared\Tests\Infrastructure;
4
5
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\Mock;
6
use Symfony\Component\Console\Input\InputInterface;
7
8
trait InputInterfaceTrait
9
{
10
    /**
11
     * @var InputInterface
12
     */
13
    private $input;
14
15
    /**
16
     * @return \Mockery\MockInterface|InputInterface
17
     */
18
    protected function getInput()
19
    {
20
        return $this->input = $this->input ?: Mock::get(InputInterface::class);
21
    }
22
23
    /**
24
     * @param string $return
25
     */
26
    protected function shouldGetInputFirstArgument($return)
27
    {
28
        $this->getInput()
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Symfony\Component\Console\Input\InputInterface.

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...
29
            ->shouldReceive('getFirstArgument')
30
            ->once()
31
            ->andReturn($return);
32
    }
33
}
34