InvalidEventHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

5 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
A notAnEventHandlingClassName() 0 4 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