Completed
Push — master ( 0ba1f3...e49bb9 )
by Freek
03:02
created

InvalidEventHandler::cannotHandleEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Spatie\EventProjector\Exceptions;
4
5
use Exception;
6
use Spatie\EventProjector\ShouldBeStored;
7
8
class InvalidEventHandler extends Exception
9
{
10
    public static function cannotHandleEvents(object $eventHandler)
11
    {
12
        $eventHandlerClass = get_class($eventHandler);
13
14
        return new static("`{$eventHandlerClass}` is not a valid event handler because it does not have a `handlesEvents` property.");
15
    }
16
17
    public static function eventHandlingMethodDoesNotExist(object $eventHandler, ShouldBeStored $event, string $methodName)
18
    {
19
        $eventHandlerClass = get_class($eventHandler);
20
        $eventClass = get_class($event);
21
22
        return new static("Tried to call `$methodName` on `$eventHandlerClass` to handle an event of class `$eventClass` but that method does not exist.");
23
    }
24
25
    public static function doesNotExist(string $eventHandlerClass)
26
    {
27
        return new static("The event handler class `{$eventHandlerClass}` does not exist.");
28
    }
29
}
30