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

ClassMap::convertToSnakeCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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