Completed
Pull Request — master (#67)
by Pablo
02:31
created

shouldWriteGuardCoverage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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

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('write')
32
            ->once()
33
            ->with($data);
34
    }
35
}
36