PhpMdToolProcessorTrait::getPhpMdToolProcessor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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

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
            ->shouldReceive('process')
32
            ->once()
33
            ->withArgs([$file, $options])
34
            ->andReturn($return);
35
    }
36
}
37