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

HookCopierTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHookCopier() 0 4 2
A shouldCopyPreCommitHook() 0 6 1
A shouldCopyCommitMsgHook() 0 6 1
A shouldCopyPrePushHook() 0 6 1
1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Tests\Infrastructure;
4
5
use PhpGitHooks\Module\Configuration\Infrastructure\Hook\HookCopier;
6
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\Mock;
7
8
trait HookCopierTrait
9
{
10
    /**
11
     * @var HookCopier
12
     */
13
    private $hookCopier;
14
15
    /**
16
     * @return \Mockery\MockInterface|HookCopier
17
     */
18
    protected function getHookCopier()
19
    {
20
        return $this->hookCopier = $this->hookCopier ?: Mock::get(HookCopier::class);
21
    }
22
23
    protected function shouldCopyPreCommitHook()
24
    {
25
        $this->getHookCopier()
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in PhpGitHooks\Module\Confi...ructure\Hook\HookCopier.

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...
26
             ->shouldReceive('copyPreCommitHook')
27
             ->once();
28
    }
29
30
    protected function shouldCopyCommitMsgHook()
31
    {
32
        $this->getHookCopier()
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in PhpGitHooks\Module\Confi...ructure\Hook\HookCopier.

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('copyCommitMsgHook')
34
             ->once();
35
    }
36
    
37
    protected function shouldCopyPrePushHook()
38
    {
39
        $this->getHookCopier()
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in PhpGitHooks\Module\Confi...ructure\Hook\HookCopier.

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...
40
             ->shouldReceive('copyPrePushHook')
41
             ->once();
42
    }
43
}
44