Issues (5)

tests/Stubs/Handlers/ReserveRoom.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\PHPCommandBus\Tests\Stubs\Handlers;
6
7
use RemotelyLiving\PHPCommandBus\Interfaces;
8
use RemotelyLiving\PHPCommandBus\Tests\Stubs\Commands;
9
use RemotelyLiving\PHPCommandBus\Tests\Stubs\Events;
10
11
class ReserveRoom implements Interfaces\Handler
12
{
13
    public function handle(object $command, Interfaces\CommandBus $bus)
14
    {
15
        \assert(($command instanceof Commands\ReserveRoom), 'Command is instance of ReserveRoom');
16
17
        yield new Events\RoomWasReserved();
0 ignored issues
show
Bug Best Practice introduced by
The expression yield new RemotelyLiving...vents\RoomWasReserved() returns the type Generator which is incompatible with the return type mandated by RemotelyLiving\PHPComman...faces\Handler::handle() of iterable|null.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
18
    }
19
}
20