GitAdapterUnitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpAdapter() 0 6 1
A findMostChangedFiles() 0 15 1
1
<?php
2
3
namespace Hgraca\Phorensic\Test\Miner\Vcs\Git;
4
5
use Hgraca\Phorensic\Miner\Vcs\Git\Console\ShellAdapter;
6
use Hgraca\Phorensic\Miner\Vcs\Git\ConsoleInterface;
7
use Hgraca\Phorensic\Miner\Vcs\Git\GitAdapter;
8
use Mockery;
9
use Mockery\MockInterface;
10
use PHPUnit_Framework_TestCase;
11
12
final class GitAdapterUnitTest extends PHPUnit_Framework_TestCase
13
{
14
    /** @var GitAdapter */
15
    private $adapter;
16
17
    /** @var string */
18
    private $repoPath;
19
20
    /** @var MockInterface|ShellAdapter */
21
    private $shell;
22
23
    /**
24
     * @before
25
     */
26
    public function setUpAdapter()
27
    {
28
        $this->repoPath = 'a/dummy/path';
29
        $this->shell = Mockery::mock(ConsoleInterface::class);
30
        $this->adapter = new GitAdapter($this->shell);
31
    }
32
33
    /**
34
     * @test
35
     *
36
     * @small
37
     */
38
    public function findMostChangedFiles()
39
    {
40
        $since = 'last month';
41
        $this->shell->shouldReceive('gitEffort')
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Hgraca\Phorensic\Miner\V...it\Console\ShellAdapter.

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...
42
            ->once()
43
            ->with($this->repoPath, $since)
44
            ->andReturn(file_get_contents(__DIR__ . '/GitAdapterUnitTest.findMostChangedFiles.in.sh'));
45
46
        $expected = include __DIR__ . '/GitAdapterUnitTest.findMostChangedFiles.out.php';
47
48
        self::assertEquals(
49
            $expected,
50
            $this->adapter->findMostChangedFiles($this->repoPath, $since)
51
        );
52
    }
53
}
54