Completed
Push — master ( a157cc...618bd3 )
by Frank
03:06
created

DotSeparatedSnakeCaseInflector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A classNameToType() 0 4 1
A typeToClassName() 0 4 1
A instanceToType() 0 4 1
1
<?php
2
3
namespace EventSauce\EventSourcing;
4
5
use function get_class;
6
7
class DotSeparatedSnakeCaseInflector implements ClassNameInflector
8
{
9 2
    public function classNameToType(string $className): string
10
    {
11 2
        return str_replace('\\_', '.', strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $className)));
12
    }
13
14 2
    public function typeToClassName(string $eventName): string
15
    {
16 2
        return str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('.', '\\ ', $eventName))));
17
    }
18
19
    /**
20
     * @param object $instance
21
     * @return string
22
     */
23 2
    public function instanceToType($instance): string
24
    {
25 2
        return $this->classNameToType(get_class($instance));
26
    }
27
}
28