InvalidEventHandler::notAnEventHandlingClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\EventProjector\Exceptions;
4
5
use Exception;
6
use Spatie\EventProjector\ShouldBeStored;
7
8
final class InvalidEventHandler extends Exception
9
{
10
    public static function eventHandlingMethodDoesNotExist(object $eventHandler, ShouldBeStored $event, string $methodName): self
11
    {
12
        $eventHandlerClass = get_class($eventHandler);
13
        $eventClass = get_class($event);
14
15
        return new static("Tried to call `$methodName` on `$eventHandlerClass` to handle an event of class `$eventClass` but that method does not exist.");
16
    }
17
18
    public static function doesNotExist(string $eventHandlerClass)
19
    {
20
        return new static("The event handler class `{$eventHandlerClass}` does not exist.");
21
    }
22
23
    public static function notAProjector(object $object)
24
    {
25
        return new static('`'.get_class($object).'` must implement Spatie\EventProcjetor\Projectors\Projector');
26
    }
27
28
    public static function notAnEventHandler(object $object)
29
    {
30
        return new static('`'.get_class($object).'` must implement Spatie\EventProjector\EventHandlers\EventHandler');
31
    }
32
33
    public static function notAnEventHandlingClassName(string $className)
34
    {
35
        return new static('`'.$className.'` must implement Spatie\EventProjector\EventHandlers\EventHandler');
36
    }
37
}
38