Completed
Push — master ( deb1d5...3324ab )
by Pablo
04:13
created

Shared/Tests/Infrastructure/CommandBusTrait.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PhpGitHooks\Module\Shared\Tests\Infrastructure;
4
5
use Bruli\EventBusBundle\CommandBus\CommandBus;
6
use Bruli\EventBusBundle\CommandBus\CommandInterface;
7
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\Mock;
8
use PhpGitHooks\Module\Tests\Infrastructure\UnitTestCase\SimilarTo;
9
10
trait CommandBusTrait
11
{
12
    /**
13
     * @var CommandBus
14
     */
15
    private $commandBus;
16
17
    /**
18
     * @return \Mockery\MockInterface|CommandBus
19
     */
20
    protected function getCommandBus()
21
    {
22
        return $this->commandBus = $this->commandBus ?: Mock::get(CommandBus::class);
23
    }
24
25
    /**
26
     * @param CommandInterface $command
27
     */
28
    protected function shouldHandleCommand(CommandInterface $command)
29
    {
30
        $this->getCommandBus()
0 ignored issues
show
The method shouldReceive does only exist in Mockery\MockInterface, but not in Bruli\EventBusBundle\CommandBus\CommandBus.

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('handle')
32
            ->once()
33
            ->with((new SimilarTo())->compare($command));
34
    }
35
}
36