ComposerFilesExtractorQueryHandlerTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getComposerFilesExtractorQueryHandler() 0 6 2
A shouldHandleComposerFilesExtractorQuery() 0 11 1
1
<?php
2
3
namespace PhpGitHooks\Module\Files\Tests\Infrastructure;
4
5
use PhpGitHooks\Module\Files\Contract\Query\ComposerFilesExtractor;
6
use PhpGitHooks\Module\Files\Contract\Query\ComposerFilesExtractorHandler;
7
use PhpGitHooks\Module\Files\Contract\Response\ComposerFilesResponse;
8
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\Mock;
9
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\SimilarTo;
10
11
trait ComposerFilesExtractorQueryHandlerTrait
12
{
13
    /**
14
     * @var ComposerFilesExtractorHandler
15
     */
16
    private $composerFilesExtractorQueryHandler;
17
18
    /**
19
     * @return \Mockery\MockInterface|ComposerFilesExtractorHandler
20
     */
21
    protected function getComposerFilesExtractorQueryHandler()
22
    {
23
        return $this->composerFilesExtractorQueryHandler = $this->composerFilesExtractorQueryHandler ?: Mock::get(
24
            ComposerFilesExtractorHandler::class
25
        );
26
    }
27
28
    /**
29
     * @param ComposerFilesExtractor $composerFilesFilesExtractorQuery
30
     * @param ComposerFilesResponse       $return
31
     */
32
    protected function shouldHandleComposerFilesExtractorQuery(
33
        ComposerFilesExtractor $composerFilesFilesExtractorQuery,
34
        ComposerFilesResponse $return
35
    ) {
36
        $this->getComposerFilesExtractorQueryHandler()
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in PhpGitHooks\Module\Files...erFilesExtractorHandler.

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...
37
             ->shouldReceive('handle')
38
             ->once()
39
             ->with((new SimilarTo())->compare($composerFilesFilesExtractorQuery))
40
             ->andReturn($return)
41
        ;
42
    }
43
}
44