shouldProcessPhpCsFixerTool()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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

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...
36
            ->shouldReceive('process')
37
            ->once()
38
            ->withArgs([$file, $level, $options])
39
            ->andReturn($return);
40
    }
41
}
42