Passed
Pull Request — 5.1 (#192)
by
unknown
04:24
created

StringUtils   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 1
eloc 6
c 1
b 1
f 0
dl 0
loc 9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValidVariableName() 0 7 1
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils;
5
6
7
class StringUtils
8
{
9
    public static function getValidVariableName(string $variableName): string
10
    {
11
        return preg_replace_callback('/^(\d+)/', static function (array $match) {
12
            $f = new \NumberFormatter('en', \NumberFormatter::SPELLOUT);
13
            $number = $f->format((int) $match[0]);
14
            return preg_replace('/[^a-z]+/i', '_', $number);
15
        }, $variableName);
16
    }
17
}
18