StringConverter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 14
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A tableize() 0 9 2
1
<?php
2
3
namespace Locastic\Loggastic\Util;
4
5
final class StringConverter
6
{
7
    /**
8
     * Converts a word into the format for the elastic document name. Converts 'ModelName' to 'model_name'.
9
     */
10
    public static function tableize(string $word): string
11
    {
12
        $tableized = preg_replace('~(?<=\\w)([A-Z])~u', '_$1', $word);
13
14
        if (null === $tableized) {
15
            throw new \RuntimeException(sprintf('preg_replace returned null for value "%s"', $word));
16
        }
17
18
        return mb_strtolower($tableized);
19
    }
20
}
21