Completed
Push — master ( f318b1...b9f34b )
by Freek
05:03 queued 43s
created

InvalidEventHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A eventHandlingMethodDoesNotExist() 0 7 1
A doesNotExist() 0 4 1
A notAProjector() 0 4 1
A notAnEventHandler() 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 eventHandlingMethodDoesNotExist(object $eventHandler, ShouldBeStored $event, string $methodName)
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
34
}
35