StringConverter::tableize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
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