Passed
Pull Request — 5.1 (#192)
by
unknown
03:02
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
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