Completed
Push — master ( 7e6a37...72960e )
by Frank
02:41
created

DotSeparatedSnakeCaseInflector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A classNameToEventName() 0 4 1
A eventNameToClassName() 0 4 1
A eventToEventName() 0 4 1
1
<?php
2
3
namespace EventSauce\EventSourcing;
4
5
use function get_class;
6
7
class DotSeparatedSnakeCaseInflector implements EventNameInflector
8
{
9 1
    public function classNameToEventName(string $className): string
10
    {
11 1
        return str_replace('\\_', '.', strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $className)));
12
    }
13
14 1
    public function eventNameToClassName(string $eventName): string
15
    {
16 1
        return str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('.', '\\ ', $eventName))));
17
    }
18
19 1
    public function eventToEventName(Event $event): string
20
    {
21 1
        return $this->classNameToEventName(get_class($event));
22
    }
23
}
24