Passed
Push — master ( 2f6942...d6d802 )
by Chris
28:11
created

ClassMap   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
dl 0
loc 19
ccs 0
cts 7
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToSnakeCase() 0 3 1
A getObjectAsKey() 0 3 1
A getClassName() 0 5 1
1
<?php
2
3
namespace WebTheory\Collection\Access;
4
5
use WebTheory\Collection\Access\Abstracts\AbstractArrayDriver;
6
use WebTheory\Collection\Access\Abstracts\AutoKeyedMapTrait;
7
use WebTheory\Collection\Contracts\ArrayDriverInterface;
8
9
class ClassMap extends AbstractArrayDriver implements ArrayDriverInterface
10
{
11
    use AutoKeyedMapTrait;
12
13
    protected function getObjectAsKey(object $item): string
14
    {
15
        return $this->convertToSnakeCase($this->getClassName($item));
16
    }
17
18
    protected function getClassName(object $class): string
19
    {
20
        $class = explode('\\', get_class($class));
21
22
        return end($class);
23
    }
24
25
    protected function convertToSnakeCase(string $class): string
26
    {
27
        return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $class));
28
    }
29
}
30