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

InvalidEventHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cannotHandleEvents() 0 6 1
A eventHandlingMethodDoesNotExist() 0 7 1
A doesNotExist() 0 4 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