Passed
Pull Request — 5.1 (#192)
by
unknown
03:02
created

StringUtils::getValidVariableName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 5
c 1
b 1
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace TheCodingMachine\TDBM\Utils;
4
5
class StringUtils
6
{
7
    public static function getValidVariableName(string $variableName): string
8
    {
9
        return preg_replace_callback('/^(\d+)/', static function (array $match) {
10
            $f = new \NumberFormatter('en', \NumberFormatter::SPELLOUT);
11
            $number = $f->format((int) $match[0]);
12
            return preg_replace('/[^a-z]+/i', '_', $number);
13
        }, $variableName);
14
    }
15
}
16