Completed
Branch module_structure (3116d9)
by Pablo
02:56
created

PrePushOriginalExecutorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrePushOriginalExecutor() 0 6 2
A shouldExecutePrePushOriginal() 0 8 1
1
<?php
2
3
namespace PhpGitHooks\Module\Git\Tests\Infrastructure;
4
5
use PhpGitHooks\Module\Git\Model\PrePushOriginalExecutorInterface;
6
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\Mock;
7
8
trait PrePushOriginalExecutorTrait
9
{
10
    /**
11
     * @var PrePushOriginalExecutorInterface
12
     */
13
    private $prePushOriginalExecutor;
14
15
    /**
16
     * @return \Mockery\MockInterface|PrePushOriginalExecutorInterface
17
     */
18
    protected function getPrePushOriginalExecutor()
19
    {
20
        return $this->prePushOriginalExecutor = $this->prePushOriginalExecutor ?: Mock::get(
21
            PrePushOriginalExecutorInterface::class
22
        );
23
    }
24
25
    /**
26
     * @param string      $remote
27
     * @param string      $url
28
     * @param string|null $return
29
     */
30
    protected function shouldExecutePrePushOriginal($remote, $url, $return)
31
    {
32
        $this->getPrePushOriginalExecutor()
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in PhpGitHooks\Module\Git\M...iginalExecutorInterface.

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...
33
            ->shouldReceive('execute')
34
            ->once()
35
            ->withArgs([$remote, $url])
36
            ->andReturn($return);
37
    }
38
}
39